Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the effect of sliding stairs with jquery

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how jquery to achieve the effect of sliding stairs, I hope you have something to gain after reading this article, let's discuss it together!

Idea: the page changes when the mouse scrolls, and when you click on the module, you can achieve the effect of which to hit.

Implementation of the code

1.html and css codes

Body,ul,li {padding: 0; margin: 0;} li {list-style: none;} # floorNav {display: none; position: fixed; top: 100px; left: 50px; width: 32px; border: 1px solid # CECECE;} # floorNav li {position: relative; width: 32px; height: 32px; border-bottom: 1px solid # CECECE; text-align: center Line-height: 32px; font-size: 12px;} # floorNav span {display: none; position: absolute; top: 0; left: 0; width: 32px; height: 32px; background: red; color: white;} # floorNav li:hover span,#floorNav li.hover span {display: block;} # floorNav li:last-child {background: red; color: white Border-bottom: none;} # header,#footer {width:1000px; height: 1000px; background: darkgoldenrod; margin: 0 auto;} # content {} # content li {width:1000px; height: 600px; margin: 0 auto; font-size: 40px; text-align: center; line-height: 600px 1F clothing 2F Beauty make-up 3F Mobile phone 4F Home Appliances 5F Digital 6F Sports 7F Home 8F Mother and Infant 9F Food 10F Book 11F Service TOP clothing Beauty make-up Mobile Appliances Digital Sports Home Mother and Child Food Book Service

two。 Next, introduce a jQuery file and write the jQuery code.

(function () {/ / define discriminant var flag = true $(window) .discrimination (function () {if (flag) {/ / show hidden staircase var scrollTop=$ (this). ScrollTop (); if (scrollTop > = 500) {$("# floorNav"). FadeIn ()} else {$("# floorNav"). FadeOut () } / / refers to which $("# content li") .each (function () {if (scrollTop > = $(this). Offset (). Top-$ (this). OuterHeight () / 2) {var index = $(this). Index () $("# floorNav li") .eq (index) .addClass ("hover") .siblings (). RemoveClass ("hover")})}) / / scroll to the appropriate position when clicked $("# floorNav li:not (: last)") .click (function () {flag=false var index = $(this) .index ()) $("html, body") .animate ({"scrollTop": $("# content li") .eq (index). Offset () .top}, flag=true $(this) .addClass ("hover"). Siblings (). RemoveClass ("hover")) $("# floorNav li:last") .click (function () {flag= false) $("html,body"). Animate ({"scrollTop": 0}, 200 flag function () {flag = true})}) after reading this article, I believe you have some understanding of "how jquery achieves the effect of sliding stairs". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

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: 267

*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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report