这次给大家带来js怎样实现横向滚动与浮动导航,js实现横向滚动与浮动导航的注意事项有哪些,下面就是实战案例,一起来看一下。
横向滚动,这个方法是见过最简洁的了。
#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; }
View Code
<p id="demo" ><p id="indemo"><p 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></p><p id="demo2"></p>
View Code
<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>
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
Atas ialah kandungan terperinci js怎样实现横向滚动与浮动导航. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!