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

Mar 16, 2018 pm 02:39 PM
javascript float scroll

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!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement an online speech recognition system using WebSocket and JavaScript How to implement an online speech recognition system using WebSocket and JavaScript Dec 17, 2023 pm 02:54 PM

How to implement an online speech recognition system using WebSocket and JavaScript

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems

How to implement an online reservation system using WebSocket and JavaScript How to implement an online reservation system using WebSocket and JavaScript Dec 17, 2023 am 09:39 AM

How to implement an online reservation system using WebSocket and JavaScript

Monitor iframe scrolling behavior Monitor iframe scrolling behavior Feb 18, 2024 pm 08:40 PM

Monitor iframe scrolling behavior

How to use JavaScript and WebSocket to implement a real-time online ordering system How to use JavaScript and WebSocket to implement a real-time online ordering system Dec 17, 2023 pm 12:09 PM

How to use JavaScript and WebSocket to implement a real-time online ordering system

JavaScript and WebSocket: Building an efficient real-time weather forecasting system JavaScript and WebSocket: Building an efficient real-time weather forecasting system Dec 17, 2023 pm 05:13 PM

JavaScript and WebSocket: Building an efficient real-time weather forecasting system

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

Simple JavaScript Tutorial: How to Get HTTP Status Code

How to get HTTP status code in JavaScript the easy way How to get HTTP status code in JavaScript the easy way Jan 05, 2024 pm 01:37 PM

How to get HTTP status code in JavaScript the easy way

See all articles