Home > Web Front-end > JS Tutorial > How to implement horizontal scrolling and floating navigation in js

How to implement horizontal scrolling and floating navigation in js

php中世界最好的语言
Release: 2018-03-16 14:39:59
Original
2106 people have browsed it

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;
}
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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

css3 chat bubble style

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template