javascript模拟滚动条实现代码

  作者:bea

其实这样代码产生些了冗余.......不如单独写个Slider类 做为第一个版本还是保存起来 有时间的话 试着单独的写个Slider类 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> #container { height:200px;_height:1
其实这样代码产生些了冗余.......不如单独写个Slider类 做为第一个版本还是保存起来 有时间的话 试着单独的写个Slider类



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">




#container {
height:200px;_height:198px;width:385px;border:1px solid #CCCCCC;
}
#container #content{
height:200px;width:370px;float:left;overflow:hidden;
}
#container #content div{
margin-top:4px;margin-left:4px;height:16px;font-size:14px;color:#666666;width:100%;
}
#container #scroll{
height:200px;width:15px;float:right;
}
.b1{width:600px; height:23px; background-image:url(/upload/2010-3/20100311163933339.gif)}
/*=========================================================*/
#container1 {
height:200px;width:400px;_width:398px;border:1px solid #999999;
}
#container1 #content1{
height:180px;width:400px;overflow:hidden;
}
#container1 #content1 td{
height:180px;width:200px;
}
#container1 #content1 td img{
height:180px;width:200px;
}
#container1 #scroll1{
height:20px;width:400px;
}
#container1 #scroll1 #block1{
width:20px;height:20px;background-color:#990000;position:absolute;
}
/*====================================================================*/
table div{height:20px; font-size:13px; margin-top:5px; color:#333333; font-weight:bold}
table img{height:160px; width:200px;}
/*====================================================================*/
.b2{background-image:url(/upload/2010-3/20100311163933545.gif); width:26px; height:34px;}
.b2-1{background:transparent url(/upload/2010-3/20100311163934864.gif) no-repeat scroll center center; width:20px; height:161px; margin-left:4px;}
.b2-2{background-image:url(/upload/2010-3/20100311163934603.gif); height:22px; width:20px; position:absolute}
.b2-3{background-image:url(/upload/2010-3/20100311163934887.gif); width:26px; height:34px;}
/*====================================================================*/
.b3{ width:840px; height:216px;border:2px solid #b50000;}
.b3-1{width:740px; height:216px; margin:0 auto; }
.b3-2{height:180px; width:100%; overflow:hidden;}
.b3-l1{height:auto; width:660px;margin:0 auto;}
.b3-l2{font-size:0px; background-image:url(/upload/2010-3/20100311163934223.gif); height:20px; width:30px; background-position:-182px 0px; float:left; }
.b3-l3{font-size:0px; background-image:url(/upload/2010-3/20100311163934223.gif);height:20px; width:600px; background-position:0px -226px; float:left;}
.b3-l4{background-image:url(/upload/2010-3/20100311163934223.gif); height:20px; width:162px; background-position:-14px 0px; position:absolute}
.b3-l5{font-size:0px; background-image:url(/upload/2010-3/20100311163934223.gif); height:20px; width:30px; background-position:-216px 0px; float:left;}
/*====================================================================*/
.b4-1{font-size:0px; height:17px; width:15px; background-image:url(/upload/2010-3/20100311163934575.gif); background-position:-15px 0; margin:0px;}
.b4-2{font-size:0px; height:166px; width:15px; background-image:url(/upload/2010-3/20100311163934575.gif); background-position:-30px 0; }
.b4-3{font-size:0px; background-image:url(/upload/2010-3/20100311163934575.gif); background-position:-45px 0; position:absolute; height:17px; width:15px; }
.b4-4{font-size:0px; height:17px; width:15px; background-image:url(/upload/2010-3/20100311163934575.gif); background-position:0 0;margin:0px;}
/*====================================================================*/
.b5-1{background:url(/upload/2010-3/20100311163934971.jpg) no-repeat; width:550px; height:520px; padding:1px;}
.b5-2{height:350px; width:300px; margin-left:50px; margin-top:50px;}
.b5-3{ margin-top:10px; margin-left:5px; height:330px; width:260px; font-size:14px;; color:#054c68; float:left; overflow:hidden}
.b5-4{font-size:16px; font-weight:bold}
.b5-5{float:right; margin-right:12px; margin-top:10px; height:330px; width:15px; }
.b5-6{position:absolute; height:10px; line-height:10px; width:15px; background-color:#c6e7f4;}




0%









0%































人族


SKY流--强大的中国选手人皇sky的成名绝技


KUA流--多不兵配合MK,前期可谓遇佛神通杀


3法流--好象只是很好打兽族,打精灵还得配合小炮


骑士狮鸠流--配合圣骑的3级光环全防心灵之火,绝对bug


飘逸流--3蛋的成名绝技,首发圣骑,打得亡灵一般没的脾气


机械流--飞机加坦克,曾经风靡一时,moon也吃亏无数


万精油--3发+火枪+小炮,不变应万变的打法


兽族


跑狼骑--狼骑的高速移动,城攻与网,拆家起来无人能敌


速飞龙--比较投机的打法,一旦投机成功,对方可以直接gg


黑白牛--配合撒满,高攻,高防,高攻速,高血,无限复活


白牛海--适合内战,无限复活且20的攻击打兽身上2倍加成


XXXX流--猎头+巫医+撒满,orc时代的bug,如今很难看到


万精油--大G+狼骑+白牛+科多,最常规的打法


不死族


蜘蛛流--蜘蛛的高功,加上不死英雄的强大魔法,强


冰甲蜘蛛流--主要对抗兽族,让蜘蛛,亡骑更难打.


西瓜流--中国天灾Ted的成名绝技,女妖给兵套个盾,象西瓜


天地双鬼--有段时间一直被精灵认为是bug.


胖子毁灭--高攻,高防,高血,且无视魔法效果


骷髅海--可以看到满天的骷髅大军(驱散法师小精灵完克)


精灵族


女猎流1--NEvsNE,一般虎MM配合大量女猎,全是MM.


女猎流2--NEvsHUM,SM女王配合大量女猎克制人族速矿


吹风流--曾经的兽族客星,华丽,飘逸,==


大树流--很多很多大树配合很多很多的ac,场面壮观


弩车流--基本只有耳闻没见过


乱矿流--Moon的成名绝技,一个矿被拆了,2个矿起来了


三远流--ACMM+鹿MM+得鲁伊大叔,把任何物体射成马蜂窝















 
1.身世
 我爱罗是第四代风影之子,也是手鞠和勘九郎的弟弟。
 当他出世时,因为砂隐忍者村资金短缺,在他的父亲的指示下,一尾守鹤被封印在我爱罗的体内,目的是为了让他成为保护村庄的强大武器。忧郁的
 由于这样做需要作出牺牲,我爱罗的母亲因此成了牺牲品。
 我爱罗由他的舅父夜叉丸养大,并由他的父亲传授忍术。由于我爱罗具备守鹤的可怕力量,村子的人憎恨和惧怕他。
 夜叉丸是唯一关照他的人,也只有夜叉丸了解我爱罗的心里其实并不想伤害任何人。可是他的父亲第四代风影并不这么想,他一直视我爱罗为村庄的一个巨大威胁。
 于是第四代风影不断地派杀手刺杀我爱罗,可是没有一次成功。最后第四代风影只好叫夜叉丸下手。夜叉丸执行命令时死在我爱罗的手上。当我爱罗发现来杀他的杀手竟然是夜叉丸时感到异常震惊和悲伤。夜叉丸死前将真相告诉我爱罗,其实他从来就没有喜欢过我爱罗。他这样做只是希望能够为他的姐姐(我爱罗的母亲)报仇。夜叉丸把许多炸药绑在身上,希望和我爱罗同归于尽。由于砂子的保护,我爱罗活了下来。意识到没有人喜欢他,我爱罗逐渐地转变成一个没有感情的人,发誓只为自己而活,从杀人中寻找乐趣,并用沙子在额头上刻了"爱"字。 由于惧怕他体内的怪兽会占据他的心灵,我爱罗从小患了失眠症,这是为什么他的眼圈是黑的缘故。平时背上背负著一个巨大的葫芦,当危机出现时,葫芦中的砂子会自动保护我爱罗。
 
2.忍术
 ·绝对防御:随身携带一部分带有查克拉的砂子,随时形成防御
 ·砂分身:用沙子造出一个分身
 ·砂瞬身:用沙子移动
 ·砂缚柩:以沙迅速靠近对手将目标包在沙内无法行动,然后用强大的压力将对手压死。
 ·砂时雨:将沙漫布于空中,然后集中一点落下以配合下一式
 ·砂手里剑:在沙中注入查克拉使之硬化,快速放出
 ·砂之铠甲:长期将魔沙覆盖于身体表面起到防御作用
 ·砂之守护Ⅰ:沙不需要我爱罗的意识自行保护
 ·守鹤半觉醒:出现一个大沙球,将自己包住,有敌人进攻沙子会自动反击。
 ·守鹤之盾:最强的终极防御术!将地下石矿中最坚硬的部分混合查克拉制成。可以抵消一切攻击。用地下最强的矿物质加查克拉做成沙瀑枪葬的盾。
 ·守鹤之矛:最强的终极攻击术!与守鹤之盾相匹配。曾用此招将[匠忍者村]的始祖击毙
 ·砂瀑送葬:用沙将对手压死,用于被沙缚柩困住的对手出招
 ·流沙瀑流:大面积操纵沙控制对手以配合砂瀑大葬
 ·砂瀑大葬:沙暴送葬强化版,范围扩大到一平方公里
 ·砂瀑枪葬:最硬绝对攻击! 用沙以棱台形包住对手,然后用巨型守鹤之矛击中对手,这招消耗在沙中注入查克拉使之硬化,快速放出查克拉特别大,杀伤力强。
 ·砂流葬:控制目标下方的沙,制成流沙,将目标陷入地下200米处压死 灭砂瀑葬
 ·灭砂瀑葬:在沙地上开出巨大裂口,使对手陷入沙层以下。当沙子完全埋没后,将查克拉
 集中于左手,使沙子放射出与地震般强大的震感爆炸力,杀伤力极强
 ·砂缚牢:沙缚柩扩大版.将困住对手的沙缚柩浮于半空利用周围的风沙配合查克拉进行方型式四面扭曲、挤压,最后爆破沙牢
 ·假寐之术(狸寝术):催眠术,让自己深度沉睡,以爆发出守鹤
 ·砂之眼:在被完全包裹住自己时,为了探清外面的情况做了一个眼睛。但是这不是普通的沙眼,和视神经是连接的
 ·砂雷针:剧场版『幻之地底遗迹』中我爱罗使用的绝招,将沙子做成针状散布在敌人四周,产生雷电攻击敌人
 .风遁·无限砂尘大突破:风遁混杂着沙子,攻击大范围内的敌人
 .风遁·练空弹:用大量查克拉压缩做成的空气波攻击敌人
 ·砂漠浮游:利用沙将自己及李洛克升到空中,以避过君麻吕恐怖之术-早蕨之舞(把大地化为尸骨)
 ·沙瀑意流:将大片的岩石化为沙子
 ·砂尘双击
 ·砂尘冥柩
 沙阵雨:,可使对手的脚无法动



 






var Sys = (function(ua){
var s = {};
s.IE = ua.match(/msie ([d.]+)/)?true:false;
s.Firefox = ua.match(/firefox/([d.]+)/)?true:false;
s.Chrome = ua.match(/chrome/([d.]+)/)?true:false;
s.IE6 = (s.IE&&([/MSIE (d).0/i.exec(navigator.userAgent)][0][1] == 6))?true:false;
s.IE7 = (s.IE&&([/MSIE (d).0/i.exec(navigator.userAgent)][0][1] == 7))?true:false;
s.IE8 = (s.IE&&([/MSIE (d).0/i.exec(navigator.userAgent)][0][1] == 8))?true:false;
return s;
})(navigator.userAgent.toLowerCase());
Sys.IE6&&document.execCommand("BackgroundImageCache", false, true);
var $ = function (id) {
return "string" == typeof id?document.getElementById(id):id;
};
var $$ = function(p,e){
return p.getElementsByTagName(e);
};
function addListener(element,e,fn){
element.addEventListener?element.addEventListener(e,fn,false):element.attachEvent("on" + e,fn)
};
function removeListener(element,e,fn){
element.removeEventListener?element.removeEventListener(e,fn,false):element.detachEvent("on" + e,fn)
};
function create(elm,parent,fn){
var element = document.createElement(elm);parent.appendChild(element);if(fn)fn(element);
};
var Css = function(e,o){
if(typeof o=="string")
{
e.style.cssText=o;
return;
}
for(var i in o)
e.style[i] = o[i];
};
function getobjpos(el,left){
var val = 0;
while (el !=null) {
val += el["offset" + (left? "Left": "Top")];
el = el.offsetParent;
}
return val;
};
var CurrentStyle = function(element){
return element.currentStyle || document.defaultView.getComputedStyle(element, null);
};
var Bind = function(object, fun) {
var args = Array.prototype.slice.call(arguments).slice(2);
return function() {
return fun.apply(object, args);
}
};
var BindAsEventListener = function(object, fun,args) {
var args = Array.prototype.slice.call(arguments).slice(2);
return function(event) {
return fun.apply(object, [event || window.event].concat(args));
}
};
var Tween = {
Linear: function(t,b,c,d){ return c*((t=t/d-1)*t*t*t*t + 1) + b; }
};
var Extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
};
var Class = function(properties){
var _class = function(){return (arguments[0] !== null && this.initialize && typeof(this.initialize) == 'function') ? this.initialize.apply(this, arguments) : this;};
_class.prototype = properties;
return _class;
};
var Drag = new Class({
options:{
Limit : false,
mxLeft : 0,
mxRight : 9999,
mxTop : 0,
mxBottom : 9999,
mxContainer : null,
LockX : false,
LockY : false,
zIndex : 2,
Onstart : function(){},
Onmove : function(){},
Onstop : function(){}
},
initialize:function(obj,options){
this._obj = obj;
this._x = 0;
this._y = 0;
this._marginLeft = 0;
this._marginTop = 0;
this._fM = BindAsEventListener(this, this.Move);
this._fS = Bind(this, this.Stop);
var o ={};
Extend(o,this.options);
Extend(o,options||{});
Extend(this,o);
this.zIndex = Math.max(this.zIndex,Drag.zIndex||0);
if(this.mxContainer&&this.Limit) //设置了限制 和 容器限制后 计算边界直
{
this.mxLeft = getobjpos(this.mxContainer,1);
this.mxTop = getobjpos(this.mxContainer,0);
this.mxRight = getobjpos(this.mxContainer,1) + this.mxContainer.offsetWidth-this._obj.offsetWidth;
this.mxBottom = getobjpos(this.mxContainer,0) + this.mxContainer.offsetHeight-this._obj.offsetHeight;
}
addListener(this._obj,"mousedown",BindAsEventListener(this,this.Start));
Drag.zIndex = this.zIndex;
},
Start:function(e){
this._obj.style.zIndex = ++Drag.zIndex;
this._x = e.clientX - this._obj.offsetLeft ;
this._y = e.clientY - this._obj.offsetTop;
this._marginLeft = parseInt(this._obj.style.marginLeft)||0;
this._marginTop = parseInt(this._obj.style.marginTop)||0;
if(Sys.IE)
{
addListener(this._obj, "losecapture", this._fS);
this._obj.setCapture();
}
else
{
e.preventDefault();
addListener(window, "blur", this._fS);
}
addListener(document,"mousemove",this._fM);
addListener(document,"mouseup",this._fS);
this.Onstart();
},
Move:function(e){
window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
var iLeft = e.clientX - this._x, iTop = e.clientY - this._y;
if(this.Limit){
iLeft= Math.min(Math.max(iLeft,this.mxLeft),this.mxRight);
iTop = Math.min(Math.max(iTop,this.mxTop),this.mxBottom);
}
if(!this.LockX)this._obj.style.left = iLeft - this._marginLeft + "px";
if(!this.LockY)this._obj.style.top = iTop - this._marginTop + "px";
this.Onmove();
},
Stop:function(){
removeListener(document,'mousemove',this._fM);
removeListener(document,'mouseup',this._fS);
if(Sys.IE)
{
removeListener(this._obj, "losecapture", this._fS);
this._obj.releaseCapture();
}
else
removeListener(window, "blur", this._fS);
this.Onstop();
}
});
var Slider = new Class({
options :{
direction : true, //true为纵,false为横
type : "Y", //分别为X,Y,N
shapechange : true, //是否该变滚动条的形状
topvalue : 0, //上或左偏差值
bottomvalue : 0, //下或右偏差值
border : 0, //处理ie下border的问题
step : 1, //键盘操作时候的步长
t : 0,
b : 0,
c : 0,
d : 40,
Onmove : function(){}
},
initialize :function(container,block,blockcontainer,options){
this.container = container;
this.block = block;
this.blockcontainer = blockcontainer;
var o ={};
Extend(o,this.options);
Extend(o,options||{});
Extend(this,o);
this.timer = null;
this.ismove = false;
var _self = this;
/*==========================================================================================================================*/
/*如果滚动条不是单独的图片可以用div模拟 这时候就得设置滚动条的长度或者宽度了 按比例设置*/
this.type =="Y"&&this.shapechange&&(this.block.style.height = this.container.offsetHeight*(this.container.offsetHeight/$$(this.container,"div")[0].scrollHeight)+"px");
this.type =="X"&&this.shapechange&&(this.block.style.width = this.container.offsetWidth*(this.container.offsetWidth/$$(this.container,"div")[0].scrollWidth)+"px");
/*==========================================================================================================================*/
var xc = this.blockcontainer?this.blockcontainer:this.container;
addListener(xc,'click',BindAsEventListener(this,this.Start));
addListener(this.block,'click',BindAsEventListener(this,this.Bubble));
/*==========================================================================================================================*/
this.KeyBind(this.container); //键盘与鼠标滑轮部分参考的cloudgamer的
this.WheelBind(this.container);
var oFocus = Sys.IE ? this.block : this.container;
addListener(this.block, "mousedown", function(){ _self.Stopmove();oFocus.focus();});
/*==========================================================================================================================*/
this.drag = new Drag(this.block,{Limit:true,mxContainer:xc,Onmove:Bind(this,this.Move)});
this.drag[this.direction?"LockX":"LockY"] = true;
this.border = (Sys.IE6||Sys.IE7)?this.border:0; //ie6,7下 border也要算进去 不然有误差 ie8,却又不需要算 真是纠结............
if(this.direction)
{
this.drag.mxTop = this.drag.mxTop - this.topvalue + this.border;
this.drag.mxBottom = this.drag.mxBottom + this.bottomvalue + this.border;
this.block.style.top = this.drag.mxTop+"px";
}
else
{
this.drag.mxLeft = this.drag.mxLeft - this.topvalue + this.border;
this.drag.mxRight = this.drag.mxRight + this.bottomvalue + this.border;
this.block.style.left = this.drag.mxLeft+"px";
}
this.Move();
},
Keycontrol : function(e){
this.Stopdefault(e);
this.Stopmove();
var l1 =this.direction?"top":"left",l2 = this.direction?"offsetTop":"offsetLeft",l3=this.direction?"mxTop":"mxLeft",l4=this.direction?"mxBottom":"mxRight";
if(e.keyCode==37||e.keyCode==38)this.block.style[l1] = Math.max(this.block[l2]-this.step,this.drag[l3]) +'px';
if(e.keyCode==39||e.keyCode==40)this.block.style[l1] = Math.min(this.block[l2]+this.step,this.drag[l4]) +'px';
this.Move();
},
Wheelcontrol :function(e){
this.Stopmove();
var t = Sys.Firefox?e.detail:e.wheelDelta;
var l1 =this.direction?"top":"left",l2 = this.direction?"offsetTop":"offsetLeft",l3=this.direction?"mxTop":"mxLeft",l4=this.direction?"mxBottom":"mxRight";
this.block.style[l1] = Sys.Firefox?(t0?Math.max(this.block[l2]-5,this.drag[l3])+'px':Math.min(this.block[l2]+5,this.drag[l4]) +'px');
this.Move();
this.Stopdefault(e);
},
WheelBind : function(o){
addListener(o, Sys.Firefox? "DOMMouseScroll" : "mousewheel", BindAsEventListener(this,this.Wheelcontrol));
},
KeyBind : function(o){
addListener(o,'keydown',BindAsEventListener(this,this.Keycontrol));
o.tabIndex = -1;
Sys.IE || (o.style.outline = "none");
},
Move : function(){
var c = $$(this.container,"div")[0] ;
/*=========================================================================================================================*/
if(this.type=="Y")c.scrollTop = (c.scrollHeight - c.offsetHeight)*(this.block.offsetTop - this.drag.mxTop)/(this.blockcontainer.offsetHeight - this.block.offsetHeight +this.topvalue+this.bottomvalue);
if(this.type=="X")c.scrollLeft = (c.scrollWidth - c.offsetWidth)*(this.block.offsetLeft - this.drag.mxLeft)/(this.blockcontainer.offsetWidth-this.block.offsetWidth+this.topvalue+this.bottomvalue);
/*上面为滚动条的计算方式*/
/*=========================================================================================================================*/
this.Onmove();
},
Start : function(e){
this.ismove = true;
this.b = this.direction?this.block.offsetTop:this.block.offsetLeft;
if(this.direction)
{
var t = Sys.Chrome?document.body.scrollTop:document.documentElement.scrollTop;
var l = (e.clientY+t)



[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]



有用  |  无用

猜你喜欢