In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use jquery library to achieve elevator navigation effect, the article is very detailed, has a certain reference value, interested friends must read it!
Basic ideas
Elevator navigation basically uses the height of the element from the page header offsetTop and the page scrolling distance scrollTop to compare the corresponding results.
1. The page scrolls to the corresponding position to realize the display and hiding of elevator navigation.
2. The page scrolls to the appropriate location, and the elevator navigation button adds or removes the corresponding class
3. Click the elevator navigation button to scroll the page and add or remove the corresponding classes for the button.
4. Click the top button to return to the top
Code implementation
Html code
Head focus picture parent-child beauty learning travel accommodation food tail parent-child beauty learning tourism accommodation food top
Css code
* {padding: 0; margin: 0;} body {font-size: 30px;} .header {width: 1100px; height: 200px; background-color: pink; margin: 0 auto;} .banner {width: 1100px; height: 400px Background-color: skyblue; margin: 0 auto;} .footer {width: 1100px; height: 300px; background-color: darkolivegreen; margin: 0 auto;} .content {width: 1100px; margin: 0 auto } .content .qinzi {width: 100%; height: 324px; background-color: rosybrown;} .content .liren {width: 100%; height: 304px; background-color: slategrey;} .content .xuexi {width: 100%; height: 300px Background-color: khaki;} .content .lvyou {width: 100%; height: 300px; background-color: greenyellow;} .content .zhusu {width: 100%; height: 300px; background-color: darkcyan;} .content .meishi {width: 100% Height: 300px; background-color: lightgreen;} .width: 50px; position: fixed; top: 150px; left: 50%; margin-left:-620px; font-size: 16px; text-align: center Li {width: 50px; height: 30px; background-color: grey; margin-bottom: 5px; line-height: 30px; list-style: none; cursor: pointer;} span {display: block; width: 50px; height: 30px Background-color: grey; margin-bottom: 5px; line-height: 30px; list-style: none; cursor: pointer;} .manag.current {background-color: hotpink;}
JavaScript code
Var flag = true; / / use throttle / / the page is just beginning to be hidden. When the page scrolls to content, the elevator navigation shows $(function () {/ / page refresh) and calls the / / encapsulation function once, switching between showing and hiding var contentTop = $(".content"). Offset (). Top; toggleTool () Function toggleTool () {if ($(document). ScrollTop () > = contentTop) {$(".clients") .fadeIn ();} else {$(".clients") .fadeOut () }} $(window) .scroll (function () {toggleTool () / / page to the appropriate location Add current class if (flag) {$('.content .w') .each (function (I, ele) {var cuHeight = ele.offsetHeight / 2) to the elevator navigation button If ($(document) .scrollTop () > = $(ele) .offset () .top-cuHeight) {$('.floor li') .eq (I) .addClass (' current') .siblings () .removeClass () }})}) / / Click the elevator navigation button, the page jumps to the appropriate location, and use animate $('.floor li') .click (function () {flag = false) in jquery $(this) .addClass ('current'). Siblings (). RemoveClass (); var index = $(this) .index (); var current = $(' .content .w') .eq (index) .offset () .top $('html,body') .stop () .animate ({scrollTop: current}, function () {flag = true;})}) $(' .floor span') .click (function () {$(this) .addClass ('current')) $('html,body'). Stop (). Animate ({scrollTop: 0})}) above are all the contents of the article "how to use the jquery Library to achieve Elevator Navigation effects". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.