This article shares the specific code of JavaScript to achieve the floor effect for your reference. The specific content is as follows * { margin: 0; padding: 0; } html, body { width: 100%; height: 100%; } ul { width: 100%; height: 100%; } ul>li { list-style: none; width: 100%; height: 100%; font-size: 100px; text-align: center; } ol { position: fixed; left: 10px; top: 50%; transform: translateY(-50%); } ol>li { list-style: none; width: 100px; line-height: 40px; text-align: center; border: 1px solid #000; } .selected { background: skyblue; } <ul> <li>I am level 1</li> <li>I am level 2</li> <li>I am level 3</li> <li>I am level 4</li> <li>I am level 5</li> </ul> <ol> <li class="selected">Layer 1</li> <li>Layer 2</li> <li>Layer 3</li> <li>Layer 4</li> <li>Layer 5</li> </ol> js: // 1. Initialize the color of the floor let oPages = document.querySelectorAll("ul>li"); let colorArr = ['green', 'blue', 'purple', 'red', 'yellow']; for (let i = 0; i < oPages.length; i++) { let page = oPages[i]; page.style.background = colorArr[i]; } // 2. Select whoever is clicked let oItems = document.querySelectorAll("ol>li"); let currentItem = oItems[0]; // Get the height of the visible area let screenHeight = getScreen().height; let timerId = null; for (let i = 0; i < oItems.length; i++) { let item = oItems[i]; item.onclick = function() { currentItem.className = ""; this.className = "selected"; currentItem = this; // Implement scrolling // window.scrollTo(0, i * screenHeight); // Note: Use documentElement.scrollTop to scroll the web page. Do not add units when setting the value. // document.documentElement.scrollTop = i * screenHeight + "px"; // document.documentElement.scrollTop = i * screenHeight; clearInterval(timerId); timerId = setInterval(function() { let begin = document.documentElement.scrollTop; let target = i * screenHeight; let step = (target - begin) * 0.2; begin += step; if (Math.abs(Math.floor(step)) <= 1) { clearInterval(timerId); document.documentElement.scrollTop = i * screenHeight; return; } document.documentElement.scrollTop = begin; }, 50); } } //Get the browser viewport width and height function getScreen() { let width, height; if (window.innerWidth) { width = window.innerWidth; height = window.innerHeight; } else if (document.compatMode === "BackCompat") { width = document.body.clientWidth; height = document.body.clientHeight; } else { width = document.documentElement.clientWidth; height = document.documentElement.clientHeight; } return { width: width, height: height } } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: 20 CSS coding tips to make you more efficient (sorted)
>>: 4 Practical Tips for Web Page Design
Why did I use this? It all started with the makin...
Table of contents 1. Object 1.1 What is an object...
Table of contents 1. Background 2. Table creation...
Install fastdfs on Docker Mount directory -v /e/f...
Mininet Mininet is a lightweight software defined...
Original : http://developer.yahoo.com/performance...
1. Environment and preparation 1. Ubuntu 14.04 2....
The difference between inline elements and block-...
HTML reuse is a term that is rarely mentioned. Tod...
Overview Indexing is a skill that must be mastere...
"/" is the root directory, and "~&...
Union is a union operation on the data, excluding...
The following is my judgment based on the data st...
This article shares the specific code for WeChat ...
Redux is a simple state manager. We will not trac...