This time I will show you how to implement horizontal scrolling and floating navigation in js, what are the precautions for implementing horizontal scrolling and floating navigation in js, as follows This is a practical case, let’s take a look at it.
Horizontal scrolling, this method is the simplest I have ever seen.
#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>
Smooth scrolling. Why did it not scroll when I used it yesterday? Then I changed the increased value of tab.srollLeft and it was fine.
2. Floating navigation:
<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>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
html5 animation to realize dancing umbrella
Development of Nodejs view and model
The above is the detailed content of How to implement horizontal scrolling and floating navigation in js. For more information, please follow other related articles on the PHP Chinese website!