一個不錯的JavaScript類比捲軸

來源:互聯網
上載者:User

JavaScript SliderBar

一個不錯的JavaScript類比捲軸,原型的優雅寫法。沒有什麼好說的,需要的就下載吧,

<br /><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br /><html xmlns="http://www.w3.org/1999/xhtml"><br /><head><br /> <title></title><br /> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><br /> <meta name="keywords" content="" /><br /> <meta name="description" content="" /><br /> <meta name="robots" content="all" /><br /> <style type="text/css"></p><p> * {margin:0; padding:0; }<br /> body {padding:50px; font-size:12px; line-height:18px; }<br /> #scrollBox,<br /> #scrollBox2 {width:100px; height:200px; border-right:1px solid #f00; padding:0 5px 0 0; position:relative;}<br /> .scrollContent {height:200px; background:#efefef; overflow:hidden;}<br /> .scrollBar {width:6px; height:20px; background:#ccc; position:absolute; right:-4px; top:0; }</p><p> </style><br /></head><br /><body><br /><div id="scrollBox"><br /> <div class="scrollContent"><br /> <ul><br /> <li>GS安全標準,確保燃燒充分,並時刻監測家中用氣環境,安全無憂</li><br /> <li>無線穿牆遙控技術,能穿三層牆,遙控三十米</li><br /> <li>精確恒溫技術,出水溫度偏差不超過±1℃</li><br /> <li>無暇外觀設計,生活細添精緻品味</li><br /> </ul><br /> </div><br /></div><br /><br /><div id="scrollBox2"><br /> <div class="scrollContent"><br /> <ul><br /> <li>GS安全標準,確保燃燒充分,並時刻監測家中用氣環境,安全無憂</li><br /> <li>無線穿牆遙控技術,能穿三層牆,遙控三十米</li><br /> <li>精確恒溫技術,出水溫度偏差不超過±1℃</li><br /> <li>無暇外觀設計,生活細添精緻品味</li><br /> <li>德國schott微晶面板,科技與藝術的完美融合</li><br /> <li>斷電記憶功能,通電後自動回復到上一次設定水溫</li><br /> <li>浴缸注水功能,自由選擇洗浴方式</li><br /> <li>智能風壓技術,安全智能控制</li><br /> <li>LED顯示,智能觸摸按鍵</li><br /> <li>節水設計,顯示水量消耗,提醒節約用水</li><br /> <li>3L/min超低水流啟動,不受水壓限制,滿足高層使用者及低水壓使用者需求</li><br /> <li>多重安全保護,時刻呵護家人</li><br /> </ul><br /> </div><br /></div><br /><script type="text/javascript"><br /> function scroll(id){<br /> var self = this;<br /> this.obj = document.getElementById(id);<br /> this.content = this.obj.getElementsByTagName('div')[0];<br /> this.bar = document.createElement('div');<br /> this.bar.className = 'scrollBar';<br /> this.bar.style.marginTop = 0;<br /> this.bar.style.height = parseInt( this.obj.offsetHeight / this.content.scrollHeight * this.obj.offsetHeight) + 'px';<br /> //parseInt(this.area.offsetHeight/this.area.scrollHeight * (this.bar.offsetHeight - this.arrowUpHeight - this.arrowDownHeight));<br /> // this.bar.innerHTML = id;<br /> this.obj.appendChild( this.bar );<br /> this.bar.y;<br /> this.srcElement;<br /> this.marginTop;<br /> this.bar.onmousedown = function(e){ self.mousedown(e); }<br /> }<br /> scroll.prototype = {<br /> mousedown:function(e){<br /> var self = this;<br /> var e = e || window.event;<br /> self.bar.y = e.clientY;<br /> self.bar.t = parseInt( self.bar.style.marginTop );<br /> document.onmousemove = function(e){ self.mousemove(e); }<br /> stopDefault(e);<br /> },<br /> mousemove:function(e){<br /> var e = e || window.event;<br /> this.marginTop = this.bar.t + ( e.clientY - this.bar.y );<br /> if( this.marginTop < 0 ) {<br /> this.marginTop = 0;<br /> }<br /> if( this.marginTop > this.obj.clientHeight - this.bar.offsetHeight ){<br /> this.marginTop = this.obj.clientHeight - this.bar.offsetHeight;<br /> }<br /> this.bar.style.marginTop = this.marginTop + 'px';<br /> this.content.scrollTop = ( this.content.scrollHeight - this.obj.offsetHeight ) * parseInt( this.marginTop ) / ( this.obj.clientHeight - this.bar.clientHeight );<br /> document.onmouseup = function(e){ document.onmousemove = null; }<br /> stopDefault(e);<br /> }<br /> }<br /> function stopDefault( e ) {<br /> if ( e && e.preventDefault )<br /> e.preventDefault();<br /> else<br /> window.event.returnValue = false;<br /> return false;<br /> }</p><p>var p = new scroll ('scrollBox' );<br />var p2 = new scroll ('scrollBox2' );<br /></script><br /></body><br /></html><br />

運行代碼

*來源於網路

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.