相思资源网 Design By www.200059.com
本文实例讲述了js实现的鼠标滚轮滚动切换页面效果的方法。分享给大家供大家参考,具体如下:
运行效果截图如下:
具体代码如下:
<!DOCTYPE html> <html> <head> <title>wheel</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <script type="text/javascript" > var currentShowPageIndex = 0; var animateTimeout = null; var isWheelAnimating = false; var isWheelUp = function(event) { event = event || window.event; var up = true; if(event.wheelDelta){//IE/Opera/Chrome up = event.wheelDelta / 120 == 1 ""; barLiList[index].className = "active"; } var changePage = function(pageIndex) { var showPageUl = document.getElementById('wheelUl'); changeBar(currentShowPageIndex, pageIndex); currentShowPageIndex = pageIndex; var left = -(currentShowPageIndex) * 1000; showPageUl.style.marginLeft = left + "px"; return; } var animate = function(obj, mode, from, to){ if(animateTimeout) { clearTimeout(animateTimeout); } if(mode == "left") { if(from > to) { from = from - 50; obj.style.marginLeft = (from) + "px"; setTimeout(function(){ animate(obj, mode, from, to); }, 30); } else { isWheelAnimating = false; } return; } if(from < to) { from = from + 50; obj.style.marginLeft = (from) + "px"; setTimeout(function(){ animate(obj, mode, from, to); }, 30); } else { isWheelAnimating = false; } } var mouseWheel = function(event) { if(isWheelAnimating) { return; } isWheelAnimating = true; var wheelUp = isWheelUp(event); var showPageUl = document.getElementById('wheelUl'); var showPageUlWidth = parseInt(showPageUl.offsetWidth); var showPageLiList = showPageUl.getElementsByTagName('li'); var showPageLiListLength = showPageLiList.length; var wheelWrapperLeft = parseInt(document.getElementById('wheelWrapper').offsetLeft); if(wheelUp && currentShowPageIndex < showPageLiListLength - 1) { changeBar(currentShowPageIndex, currentShowPageIndex + 1); currentShowPageIndex ++; var left = -(currentShowPageIndex) * 1000; //animate(showPageUl, "right", -(currentShowPageIndex - 1) * 1000, -(currentShowPageIndex - 1) * 1000); var from = -(currentShowPageIndex - 1) * 1000; var to = -(currentShowPageIndex) * 1000; animate(showPageUl, "left", from, to); return; } if(!wheelUp && currentShowPageIndex > 0) { changeBar(currentShowPageIndex, currentShowPageIndex - 1); currentShowPageIndex --; var from = -(currentShowPageIndex + 1) * 1000; var to = -(currentShowPageIndex) * 1000; animate(showPageUl, "right", from, to); return; } isWheelAnimating = false; }; if(document.addEventListener){ document.addEventListener('DOMMouseScroll',function(event) { mouseWheel(event); },false); } document.onmousewheel = function(event) { mouseWheel(event); } window.onload = function(){ var barUl = document.getElementById('barUl'); var barLiList = barUl.getElementsByTagName('li'); for(var i=0,length=barLiList.length; i<length; i++) { (function(index){ barLiList[index].onclick = function(){ changePage(index); }; })(i); } } </script> <style type="text/css" > body { background:#494949; margin:0; } ul { list-style:none; margin:0; padding:0; } li { float:left;} #wheelWrapper { width:1000px; height:550px; margin:0 auto; position:fixed; left:50%; margin-left:-505px; bottom:50px; overflow:hidden; } #wheelUl { width:5050px; height:500px; } #barUl { clear:both; margin:0 auto; width:550px; margin-top:20px; line-height:25px; } #barUl>li { width:100px; background:orange; height:25px; margin-right:10px; border-radius:5px; text-align:center; -webkit-border-radius:5px; -moz-border-radius:5px; } #barUl>li:hover { background:#C36C12; } #barUl>li[class=active] { background:#C36C12; } #wheelUl>li { width:1000px; } .wheel { width:994px; height:500px; background:#FAAA3C; border-radius:10px; -webkit-border-radius:10px; -moz-border-radius:10px; margin:0 auto; line-height:300px; font-size:100px; text-align:center; } .radius { border-radius:3px; -webkit-border-radius:3px; -moz-border-radius:3px; } h1 { text-align:center; color:#fff; } </style> </head> <body id="body"> <h1 >ie8+,chrome,ff提供支持</h1> <div id="wrapper"> <div id="wheelWrapper"> <ul id="wheelUl" > <li > <div class="wheel"> 1_page1 </div> </li> <li > <div class="wheel"> 2_page2 </div> </li> <li > <div class="wheel"> 3_page3 </div> </li> <li > <div class="wheel"> 4_page4 </div> </li> <li > <div class="wheel"> 5_page5 </div> </li> </ul> <ul id="barUl"> <li class="active"> 1 </li> <li> 2 </li> <li> 3 </li> <li> 4 </li> <li> 5 </li> </ul> </div> </div> </body> </html>
更多关于jQuery特效相关内容感兴趣的读者可查看本站专题:《jQuery常见经典特效汇总》及《jQuery动画与特效用法总结》
希望本文所述对大家jQuery程序设计有所帮助。
标签:
js,鼠标滚动,切换页面
相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com
暂无js实现的鼠标滚轮滚动切换页面效果(类似360默认页面滚动切换效果)的评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。