JS自定義滾動(dòng)條效果
本文實(shí)例為大家分享了JS自定義滾動(dòng)條的具體代碼,供大家參考,具體內(nèi)容如下
<head> <meta charset='UTF-8'> <title></title> <style type='text/css'> #all{ width: 500px; height: 50px; background-color: sandybrown; border-radius: 25px; margin: 0 auto; position: relative; } #div1{ width: 50px; height: 50px; border-radius: 50%; background-color: rosybrown; position: absolute; } #box{ background-color: yellow; position: absolute; top: 200px; left: 200px; } </style></head><body> <div id='all'> <div id='div1'></div> </div> <div id='box'></div> <script type='text/javascript'> var oAll = document.getElementById('all'); var oDiv1 = document.getElementById('div1'); var oBox = document.getElementById('box'); var maxL = oAll.clientWidth - oDiv1.offsetWidth; oDiv1.onmousedown = function(){ var ev = ev || window.event; var lessX = ev.clientX - oDiv1.offsetLeft; document.onmousemove = function(){ var ev = ev || window.event; var posL = ev.clientX - lessX; if(posL<0){ posL = 0; } if(posL>maxL){ posL = maxL; } oDiv1.style.left = posL + 'px'; //滾動(dòng)條移動(dòng)的百分比 //oDiv1.offsetLeft/maxL var per = posL/maxL; //定義寬0~300 oBox.style.width = 300*per+'px'; oBox.style.height = 300*per+'px'; oBox.style.marginTop = -oBox.offsetHeight/2+'px'; oBox.style.marginLeft = -oBox.offsetWidth/2+'px'; } } document.onmouseup =function(){ document.onmousemove = null; } </script></body>
更多關(guān)于滾動(dòng)效果的精彩文章點(diǎn)擊下方專題:
javascript滾動(dòng)效果匯總
jquery滾動(dòng)效果匯總
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. jsp+servlet簡(jiǎn)單實(shí)現(xiàn)上傳文件功能(保存目錄改進(jìn))2. .Net反向代理組件Yarp用法詳解3. 解決request.getParameter取值后的if判斷為NULL的問(wèn)題4. .NET Framework各版本(.NET2.0 3.0 3.5 4.0)區(qū)別5. 詳解JSP 內(nèi)置對(duì)象request常見用法6. JSP中param動(dòng)作的實(shí)例詳解7. ASP.NET MVC實(shí)現(xiàn)下拉框多選8. ASP.NET MVC增加一條記錄同時(shí)添加N條集合屬性所對(duì)應(yīng)的個(gè)體9. .NET中的MassTransit分布式應(yīng)用框架詳解10. ASP.NET MVC實(shí)現(xiàn)本地化和全球化
