从csdn的blog上转过来的  做了些修改

其实写的比较糟糕(我指的是构造) 我用的是以前的一个drag类  在这个基础上在的来完成的Slider

其实这样代码产生些了冗余.......不如单独写个Slider类     做为第一个版本还是保存起来  有时间的话 试着单独的写个Slider类
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title></title> <style type="text/css"> #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(http://album.hi.csdn.net/app_uploads/wtcsy/20090602/171203276.p.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(http://album.hi.csdn.net/app_uploads/wtcsy/20090831/103129203.p.gif); width:26px; height:34px;} .b2-1{background:transparent url(http://album.hi.csdn.net/app_uploads/wtcsy/20090831/103129125.p.gif) no-repeat scroll center center; width:20px; height:161px; margin-left:4px;} .b2-2{background-image:url(http://album.hi.csdn.net/app_uploads/wtcsy/20090831/103129000.p.gif); height:22px; width:20px; position:absolute} .b2-3{background-image:url(http://album.hi.csdn.net/app_uploads/wtcsy/20090831/103128390.p.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(http://album.hi.csdn.net/app_uploads/wtcsy/20090902/232151437.p.gif); height:20px; width:30px; background-position:-182px 0px; float:left; } .b3-l3{font-size:0px; background-image:url(http://album.hi.csdn.net/app_uploads/wtcsy/20090902/232151437.p.gif);height:20px; width:600px; background-position:0px -226px; float:left;} .b3-l4{background-image:url(http://album.hi.csdn.net/app_uploads/wtcsy/20090902/232151437.p.gif); height:20px; width:162px; background-position:-14px 0px; position:absolute} .b3-l5{font-size:0px; background-image:url(http://album.hi.csdn.net/app_uploads/wtcsy/20090902/232151437.p.gif); height:20px; width:30px; background-position:-216px 0px; float:left;} /*====================================================================*/ .b4-1{font-size:0px; height:17px; width:15px; background-image:url(http://album.hi.csdn.net/app_uploads/wtcsy/20090831/145213218.p.gif); background-position:-15px 0; margin:0px;} .b4-2{font-size:0px; height:166px; width:15px; background-image:url(http://album.hi.csdn.net/app_uploads/wtcsy/20090831/145213218.p.gif); background-position:-30px 0; } .b4-3{font-size:0px; background-image:url(http://album.hi.csdn.net/app_uploads/wtcsy/20090831/145213218.p.gif); background-position:-45px 0; position:absolute; height:17px; width:15px; } .b4-4{font-size:0px; height:17px; width:15px; background-image:url(http://album.hi.csdn.net/app_uploads/wtcsy/20090831/145213218.p.gif); background-position:0 0;margin:0px;} /*====================================================================*/ .b5-1{background:url(http://album.hi.csdn.net/app_uploads/wtcsy/20090909/111957390.p.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;} </style> </head> <body style=" padding:30px; margin:0px;"> <br> <div id='a1' class="b1" > <img id='block1' src='http://album.hi.csdn.net/app_uploads/wtcsy/20090602/171041823.p.gif' style="position: absolute; margin-top:3px;"> </div> <div id='info1'>0%</div> <br> <div> <div class="b2"></div> <div id="a2" class="b2-1"> <div id='block2' class="b2-2"></div> </div> <div class="b2-3"></div> </div> <div id='info2'>0%</div> <br> <div class="b3"> <div id="a3" class="b3-1"> <div class="b3-2"> <table width="1680" height="180" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="210" align="center"> <img src='http://comic.qq.com/images/comic/2007/11/13/tj/09.jpg'> </td> <td width="210" align="center"> <img src="http://comic.qq.com/z/naruto/images/tr/tr7/s/08.jpg"> </td> <td width="210" align="center"> <img src="http://comic.qq.com/images/comic/2005/04/29/pt2/16.jpg"> </td> <td width="210" align="center"> <img src="http://comic.qq.com/images/tj/index/autopic/ceshi/20060207ceshi01.jpg"> </td> <td width="210" align="center"> <img src="http://comic.qq.com/images/comic/2006/04/13/tr/comicqq23.jpg"> </td> <td width="210" align="center"> <img src="http://comic.qq.com/images/comic/2008/10/13/gpt/5.jpg"> </td> <td width="210" align="center"> <img src="http://comic.qq.com/images/comic/2008/10/13/gpt/2.jpg"> </td> <td width="210" align="center"> <img src="http://comic.qq.com/images/comic/2008/10/13/gpt/8.jpg"> </td> </tr> </table> </div> <div class="b3-l1"> <div id='la' class="b3-l2"></div> <div id="scroll3" class="b3-l3"> <div id ="block3" class="b3-l4"></div> </div> <div id='r' class="b3-l5"></div> </div> </div> </div> <br> <div id="container"> <div id="content"> <div>人族</div> <div>SKY流--强大的中国选手人皇sky的成名绝技</div> <div>KUA流--多不兵配合MK,前期可谓遇佛神通杀</div> <div>3法流--好象只是很好打兽族,打精灵还得配合小炮</div> <div>骑士狮鸠流--配合圣骑的3级光环全防心灵之火,绝对bug</div> <div>飘逸流--3蛋的成名绝技,首发圣骑,打得亡灵一般没的脾气</div> <div>机械流--飞机加坦克,曾经风靡一时,moon也吃亏无数</div> <div>万精油--3发+火枪+小炮,不变应万变的打法</div> <div>兽族</div> <div>跑狼骑--狼骑的高速移动,城攻与网,拆家起来无人能敌</div> <div>速飞龙--比较投机的打法,一旦投机成功,对方可以直接gg</div> <div>黑白牛--配合撒满,高攻,高防,高攻速,高血,无限复活</div> <div>白牛海--适合内战,无限复活且20的攻击打兽身上2倍加成</div> <div>XXXX流--猎头+巫医+撒满,orc时代的bug,如今很难看到</div> <div>万精油--大G+狼骑+白牛+科多,最常规的打法</div> <div>不死族</div> <div>蜘蛛流--蜘蛛的高功,加上不死英雄的强大魔法,强</div> <div>冰甲蜘蛛流--主要对抗兽族,让蜘蛛,亡骑更难打.</div> <div>西瓜流--中国天灾Ted的成名绝技,女妖给兵套个盾,象西瓜</div> <div>天地双鬼--有段时间一直被精灵认为是bug.</div> <div>胖子毁灭--高攻,高防,高血,且无视魔法效果</div> <div>骷髅海--可以看到满天的骷髅大军(驱散法师小精灵完克)</div> <div>精灵族</div> <div>女猎流1--NEvsNE,一般虎MM配合大量女猎,全是MM.</div> <div>女猎流2--NEvsHUM,SM女王配合大量女猎克制人族速矿</div> <div>吹风流--曾经的兽族客星,华丽,飘逸,==</div> <div>大树流--很多很多大树配合很多很多的ac,场面壮观</div> <div>弩车流--基本只有耳闻没见过</div> <div>乱矿流--Moon的成名绝技,一个矿被拆了,2个矿起来了</div> <div>三远流--ACMM+鹿MM+得鲁伊大叔,把任何物体射成马蜂窝</div> </div> <div id="scroll"> <div id='p1' class="b4-1"></div> <div id="scroll4" class="b4-2"> <div id="block4" class="b4-3"> </div> </div> <div id='p2' class="b4-4"></div> </div> </div> <br> <div class="b5-1"> <div id='con1' class="b5-2"> <div id='ccc1' class="b5-3">   <span class="b5-4">1.身世</span><br>   我爱罗是第四代风影之子,也是手鞠和勘九郎的弟弟。<br>   当他出世时,因为砂隐忍者村资金短缺,在他的父亲的指示下,一尾守鹤被封印在我爱罗的体内,目的是为了让他成为保护村庄的强大武器。忧郁的<br>   由于这样做需要作出牺牲,我爱罗的母亲因此成了牺牲品。<br>   我爱罗由他的舅父夜叉丸养大,并由他的父亲传授忍术。由于我爱罗具备守鹤的可怕力量,村子的人憎恨和惧怕他。<br>   夜叉丸是唯一关照他的人,也只有夜叉丸了解我爱罗的心里其实并不想伤害任何人。可是他的父亲第四代风影并不这么想,他一直视我爱罗为村庄的一个巨大威胁。   于是第四代风影不断地派杀手刺杀我爱罗,可是没有一次成功。最后第四代风影只好叫夜叉丸下手。夜叉丸执行命令时死在我爱罗的手上。当我爱罗发现来杀他的杀手竟然是夜叉丸时感到异常震惊和悲伤。夜叉丸死前将真相告诉我爱罗,其实他从来就没有喜欢过我爱罗。他这样做只是希望能够为他的姐姐(我爱罗的母亲)报仇。夜叉丸把许多炸药绑在身上,希望和我爱罗同归于尽。由于砂子的保护,我爱罗活了下来。意识到没有人喜欢他,我爱罗逐渐地转变成一个没有感情的人,发誓只为自己而活,从杀人中寻找乐趣,并用沙子在额头上刻了“爱”字。<br> 由于惧怕他体内的怪兽会占据他的心灵,我爱罗从小患了失眠症,这是为什么他的眼圈是黑的缘故。平时背上背负著一个巨大的葫芦,当危机出现时,葫芦中的砂子会自动保护我爱罗。<br><br>   <span class="b5-4">2.忍术</span><br>   ·绝对防御:随身携带一部分带有查克拉的砂子,随时形成防御<br>   ·砂分身:用沙子造出一个分身<br>   ·砂瞬身:用沙子移动<br>   ·砂缚柩:以沙迅速靠近对手将目标包在沙内无法行动,然后用强大的压力将对手压死。<br>   ·砂时雨:将沙漫布于空中,然后集中一点落下以配合下一式<br>   ·砂手里剑:在沙中注入查克拉使之硬化,快速放出<br>   ·砂之铠甲:长期将魔沙覆盖于身体表面起到防御作用<br>   ·砂之守护Ⅰ:沙不需要我爱罗的意识自行保护<br>   ·守鹤半觉醒:出现一个大沙球,将自己包住,有敌人进攻沙子会自动反击。<br>   ·守鹤之盾:最强的终极防御术!将地下石矿中最坚硬的部分混合查克拉制成。可以抵消一切攻击。用地下最强的矿物质加查克拉做成沙瀑枪葬的盾。<br>   ·守鹤之矛:最强的终极攻击术!与守鹤之盾相匹配。曾用此招将[匠忍者村]的始祖击毙<br>   ·砂瀑送葬:用沙将对手压死,用于被沙缚柩困住的对手出招<br>   ·流沙瀑流:大面积操纵沙控制对手以配合砂瀑大葬<br>   ·砂瀑大葬:沙暴送葬强化版,范围扩大到一平方公里<br>   ·砂瀑枪葬:最硬绝对攻击! 用沙以棱台形包住对手,然后用巨型守鹤之矛击中对手,这招消耗在沙中注入查克拉使之硬化,快速放出查克拉特别大,杀伤力强。<br>   ·砂流葬:控制目标下方的沙,制成流沙,将目标陷入地下200米处压死 灭砂瀑葬<br>   ·灭砂瀑葬:在沙地上开出巨大裂口,使对手陷入沙层以下。当沙子完全埋没后,将查克拉<br>   集中于左手,使沙子放射出与地震般强大的震感爆炸力,杀伤力极强<br>   ·砂缚牢:沙缚柩扩大版.将困住对手的沙缚柩浮于半空利用周围的风沙配合查克拉进行方型式四面扭曲、挤压,最后爆破沙牢<br>   ·假寐之术(狸寝术):催眠术,让自己深度沉睡,以爆发出守鹤<br>   ·砂之眼:在被完全包裹住自己时,为了探清外面的情况做了一个眼睛。但是这不是普通的沙眼,和视神经是连接的<br>   ·砂雷针:剧场版『幻之地底遗迹』中我爱罗使用的绝招,将沙子做成针状散布在敌人四周,产生雷电攻击敌人<br>   .风遁·无限砂尘大突破:风遁混杂着沙子,攻击大范围内的敌人<br>   .风遁·练空弹:用大量查克拉压缩做成的空气波攻击敌人<br>   ·砂漠浮游:利用沙将自己及李洛克升到空中,以避过君麻吕恐怖之术-早蕨之舞(把大地化为尸骨)<br>   ·沙瀑意流:将大片的岩石化为沙子<br>   ·砂尘双击 <br>   ·砂尘冥柩 <br>   沙阵雨:,可使对手的脚无法动<br> </div> <div id='scroll5' class="b5-5"> <div id="block5" class="b5-6">&nbsp;</div> </div> <div style="clear:both"></div> </div> </div> <script language="javascript"> 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?(t<0?Math.max(this.block[l2]-5,this.drag[l3])+'px':Math.min(this.block[l2]+5,this.drag[l4]) +'px'):(t>0?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)<=this.block.offsetTop?0:this.block.offsetHeight; } else { var t = Sys.Chrome?document.body.scrollLeft:document.documentElement.scrollLeft; var l = (e.clientX+t)<=this.block.offsetLeft?0:this.block.offsetWidth; } this.c = this.direction?(e.clientY+t-l):(e.clientX+t-l); this.t = 0; this.Run(); }, Run : function(){ if(!this.ismove)return; clearTimeout(this.timer); if(this.t<this.d) { this.Runto(Math.round(Tween.Linear(this.t++,this.b,(this.c-this.b),this.d))); this.timer = setTimeout(Bind(this,this.Run),5); } else { this.Runto(this.c); this.t=0; this.ismove = true; } }, Runto : function(i){ this.block.style[this.direction?"top":"left"] = i + "px"; this.Move(); }, Bubble : function(e){ Sys.IE?(e.cancelBubble=true):(e.stopPropagation()); }, Stopdefault : function(e){ Sys.IE?(e.returnValue = false):(e.preventDefault()); }, Left : function(o){ this.Lrmove("mxTop","mxLeft"); }, Right : function(){ this.Lrmove("mxBottom","mxRight"); }, Lrmove : function(t,b){ if(this.t!=0)return; this.ismove = true; this.b = this.direction?this.block.offsetTop:this.block.offsetLeft; this.c = this.direction?this.drag[t]:this.drag[b]; this.Run(); }, Stopmove : function(){ this.ismove=false;clearTimeout(this.time);this.t = 0; } }) window.onload = function(){ //================================================================================================ new Slider($('a1'),$('block1'),null,{direction:false,type:"N",Onmove:function(){ $('info1').innerHTML = parseInt((this.block.offsetLeft - this.drag.mxLeft)/(this.container.offsetWidth-this.block.offsetWidth)*100) + "%"; }}); //================================================================================================ new Slider($('a2'),$('block2'),null,{type:"S",Onmove:function(){ $('info2').innerHTML = parseInt((this.block.offsetTop - this.drag.mxTop)/(this.container.offsetHeight-this.block.offsetHeight)*100) + "%"; }}); //================================================================================================ var deom3 = new Slider($('a3'),$("block3"),$("scroll3"),{shapechange:false,direction:false,type:"X",topvalue:5,bottomvalue:5,border:2}); addListener($('la'),'click',Bind(deom3,deom3.Left)); addListener($('r'),'click',Bind(deom3,deom3.Right)); //================================================================================================ var deom4=new Slider($('container'),$('block4'),$('scroll4'),{shapechange:false,topvalue:11,bottomvalue:12,border:1}); addListener($('p1'),'click',Bind(deom4,deom4.Left)); addListener($('p2'),'click',Bind(deom4,deom4.Right)); //================================================================================================ new Slider($('con1'),$('block5'),$('scroll5')); } </script> </body> </html>

转载于:https://www.cnblogs.com/wtcsy/archive/2010/03/11/1683537.html

模拟滚动条.......相关推荐

  1. javascript 实现模拟滚动条,但不支持鼠标滚轮

    模拟滚动条做项目的时候,很多时候会用到,所以就写了一个这么模拟滚动条,但是不支持滚轮事件 <!doctype html> <html lang="en"> ...

  2. javascript之模拟滚动条

    demo代码如下: <!DOCTYPE html> <html> <head lang="en"><meta charset=" ...

  3. div横向模拟滚动条,带懒加载

    之前工作需要,在网上找了一个横向的div模拟滚动条的方法,后来有自己改动了下,在相关js中加了一个懒加载的方法,贴出来大家一起学习下 首先贴出相当于插件的scrolltools.js var inde ...

  4. html任务3 模拟滚动条,vue3系列:vue3.0自定义虚拟滚动条V3Scroll|vue3模拟滚动条组件...

    /** * @Desc Vue3.0虚拟滚动条组件V3Scroll * @Time andy by 2021-01 * @About Q:282310962 wx:xy190310*/ props: ...

  5. 针对模拟滚动条插件(jQuery.slimscroll.js)的修改

    在开发过程中程序员总会碰到产品经理提出的各种稀奇古怪的需求,尽管有些需求很奇葩,但不得不说有些须有还是能指引我们不断的学习与进步,最近在工作中就碰到这种问题.需求是要求在各主流浏览器上使用自定义的滚动 ...

  6. Div Scroll Bar (用层模拟滚动条)

    对Div的盒模型以及Css控制定位都不熟,所以遇到了不少BT问题--好在最终突破了种种困难,基本实现了自己想要的效果. 说明: 最大的突破是通过了 xhtml1-transitional.dtd 验证 ...

  7. Python:模拟登录、点击和执行 JavaScript 语句案例

    案例一:网站模拟登录 # douban.pyfrom selenium import webdriver from selenium.webdriver.common.keys import Keys ...

  8. vuejs滚动条_Vue.js 桌面端虚拟滚动条|vue美化滚动条VScroll

    介绍 VScroll 一款基于vue2.x构建的桌面PC端自定义模拟滚动条组件.支持自定义是否原生滚动条.自动隐藏.滚动条大小.层级及颜色等功能.拥有丝滑般的原生滚动条体验! 除了垂直滚动条,同样的也 ...

  9. python 模拟浏览器selenium 微信_Spider-Python爬虫之使用Selenium模拟浏览器行为

    分析 他的代码比较简单,主要有以下的步骤:使用BeautifulSoup库,打开百度贴吧的首页地址,再解析得到id为new_list标签底下的img标签,最后将img标签的图片保存下来. header ...

最新文章

  1. MATLAB【九】————ICP算法实现
  2. 为什么 SSH 的默认端口是 22 ?
  3. shell 脚本定时创建月份表
  4. 数据大屏产品介绍PPT_有这些图表美化工具,十分钟配出炫酷的数据可视化大屏...
  5. 深入理解Netscaler INat
  6. antd table排序 vue_antd of Vue 之table组件踩坑记
  7. php make test 作用,larablog 系列文章 06 - 测试:使用 PHPUnit 进行单元和功能测试
  8. c常用算法程序集_10万赞的AI算法集:含python,java,C,C++多种语言
  9. pku 1325 Machine Schedule(匈牙利算法)
  10. SinoBBD:以后发优势提供不一样的一体化融合CDN服务
  11. 查看已安装java插件_记录下eclipse下的插件安装,查看及删除方式
  12. .NET Remoting学习笔记(二)激活方式
  13. webpack手动构建vue和vue-cli构建使用 px2rem-loader ,全局自动转换px单位,让自适应来的更简单点!...
  14. 回答工作做好了,可能有三种情形
  15. IOS视频播放器的使用(MPMoviePlayerController)
  16. 讲座 | lidar目标检测------图森未来CTO王乃岩
  17. 成长型思维方式对工程师的至关重要
  18. MIUI12或android11找不到QQ文件的问题
  19. 传统书店遭遇网店逼宫 价格成为销售软肋
  20. 实用工具和网站合集分享

热门文章

  1. 光 颜色 波长 眼睛
  2. 利用python爬取知乎评论_一个简单的python爬虫,爬取知乎
  3. poi设置word表格单元格宽度_java poi 设置word 格式如表格一类的
  4. 酷派大神F2使用QPST进行nv备份恢复,解决无信号问题
  5. 前端React教程第六课 虚拟DOM
  6. 184、商城业务-检索服务-页面基本数据渲染
  7. 如何成为一名合格的学者---从写好一篇学术论文谈起 ---孟德宇
  8. 上海一级计算机试卷,上海计算机一级考试试题及答案
  9. 苹果呼叫转移设置不了_苹果手机也可以开启电信VoLTE!
  10. 嵌入式开发——程序跑飞原因总结