【吉光片羽】js横向滚动与浮动导航
2014-12-25 10:41 stoneniqiu 阅读(491) 评论(0) 编辑 收藏 举报1.横向滚动,这个方法是见过最简洁的了。
#demo { background: #FFF; overflow: hidden; border: 1px dashed #CCC; width: 1170px;border: 1px solid red; margin-left: 10px; } #demo img { border: 3px solid #F2F2F2; } #indemo { float: left; width: 800%; } #demo1 { float: left; } #demo2 { float: left; }
<div id="demo" > <div id="indemo"> <div id="demo1"> <a href="#"><img src="../Images/jiameng/1.png" border="0" /></a> <a href="#"><img src="../Images/jiameng/2.png" border="0" /></a> <a href="#"><img src="../Images/jiameng/3.png" border="0" /></a> <a href="#"><img src="../Images/jiameng/4.png" border="0" /></a> <a href="#"><img src="../Images/jiameng/5.png" border="0" /></a> <a href="#"><img src="../Images/jiameng/6.png" border="0" /></a> <a href="#"><img src="../Images/jiameng/7.png" border="0" /></a> <a href="#"><img src="../Images/jiameng/8.png" border="0" /></a> </div> <div id="demo2"></div>
<script> var speed = 10; var tab = document.getElementById("demo"); var tab1 = document.getElementById("demo1"); var tab2 = document.getElementById("demo2"); tab2.innerHTML = tab1.innerHTML; function Marquee() { if (tab2.offsetWidth - tab.scrollLeft <= 0) { tab.scrollLeft -= tab1.offsetWidth; } else { tab.scrollLeft += 2; } } var MyMar = setInterval(Marquee, speed); tab.onmouseover = function () { clearInterval(MyMar); }; tab.onmouseout = function () { MyMar = setInterval(Marquee, speed); }; </script>
滚动平滑。昨天用的时候怎么就是不滚动,然后改了tab.srollLeft的增加的值就好了。
2.浮动导航:
<script type="text/javascript" src="http://misc.jjcdn.com/resource/js/waypoints.js"></script> <script type="text/javascript"> //浮动导航 waypoints.js $('#main-nav-holder').waypoint(function (event, direction) { $(this).parent().toggleClass('sticky', direction === "down"); event.stopPropagation(); }); </script>
关注书山有路,用自己的知识体系去丈量世界!
你的关注和支持是我写作的最大动力~
书山有路群:452450927
你的关注和支持是我写作的最大动力~
书山有路群:452450927