<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>jquery Floor Effects </title>
<script src= "Https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" ></script>
<script src= "Http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js" ></script >
<script>
$ (function () {
$ (window). Scroll (function () {//Get scroll bar
var winh=$ (window). height ();//Gets the width of the visible area of the window
var scrolltop=$ (window). scrolltop ();
if (scrolltop>=$ ("#header"). Height ()) {//when the length of the scroll is greater than the height of the header, the "stair" and "back to top" fade in
$ ("#stairs"). FadeIn ();
$ ("#top"). FadeIn ();
each () traversal gets to find all the floors (i= index, el= current element)
$ ('. Floor '). Each (function (I,el) {
Get the distance from each floor to the top of the browser's viewable area
var floor_top=$ (EL). Offset (). Top;
if (winh+scrolltop-$ (this). Offset (). TOP>=WINH/2) {//the height of the viewable area of the window + the height of the current element--half the height of the currently visible area of the >= window
$ ("#stairs li"). EQ (i). addclass ("on"). Siblings (). Removeclass ("on");
}
})
}else {//otherwise, when the length of the scroll is greater than the header height, the "stair" and "back to top" fade out
$ ("#stairs"). FadeOut ();
$ ("#top"). FadeOut ();
}
})
Click to highlight//event delegate
$ ("#stairs"). On ("Click", "Li", function () {
$ (this). addclass (' on '). Siblings (). Removeclass ("on");
var index=$ (this). index ();
Console.log (index);
Click Back to the corresponding floor
var floor_scrolltop=$ (". Floor"). EQ (index). Offset (). Top;
Get the corresponding index of the floor, distance from the top
$ ("Html,body"). Stop (). Animate ({"ScrollTop": Floor_scrolltop},500,function () {
})
})
Back to Top
$ ("#top"). Click (function () {
$ ("Html,body"). Animate ({
"ScrollTop": 0
},500)
})
})
</script>
<style>
*{
margin:0px;
padding:0px;
}
#header {
height:200px;
Background-color:lightskyblue;
font-size:50px;
line-height:200px;
Text-align:center;
}
. floor {
height:1000px;
Color:white;
font-size:80px;
line-height:1000px;
Text-align:center;
}
#footer {
height:600px;
Color:white;
font-size:50px;
line-height:400px;
Text-align:center;
Background-color: #9c2f06;
}
ul{
List-style:none;
z-index:110000;
Position:absolute;
left:10px;
top:100px;
width:100px;
border:1px solid white;
Text-align:center;
Background-color:gray;
opacity:0.8;
Display:none;
position:fixed;
}
li{
Color:white;
border:1px solid white;
width:100px;
height:60px;
line-height:50px;
}
#top {
height:40px;
width:60px;
BORDER:1PX solid black;
line-height:40px;
Background-color:gray;
font-size:15px;
Font-weight:bold;
Color:white;
Text-align:center;
z-index:200;
border-radius:5px;
position:fixed;
top:900px;
left:1830px;
Display:none;
}
#stairs Li:hover span{display:block;background-color:lightpink;height:60px}
#stairs li:hover Em{display:none;}
span{
Display:none;
}
. on{background-color:red}
</style>
<body>
<ul id= "Stairs" >
<li class= "on" >
<em>1F</em>
<span> Apparel </span>
</li>
<li> <em>2F</em>
<span> Beauty </span>
</li>
<li>
<em>3F</em>
<span> Mobile </span>
</li>
<li>
<em>4F</em>
<span> Appliances </span>
</li>
<li>
<em>5F</em>
<span> Digital </span>
</li>
<li>
<em>6F</em>
<span> Sports </span>
</li>
<li>
<em>7F</em>
<span> Home </span>
</li>
<li>
<em>8F</em>
<span> Maternity </span>
</li>
<li>
<em>9F</em>
<span> Food </span>
</li>
<li>
<em>10F</em>
<span> Books </span>
</li>
<li>
<em>11F</em>
<span> Services </span>
</li>
</ul>
<div id= "Top" >goTop</div>
<div id= "Header" > Head </div>
<div id= "Main" >
<div class= "Floor" style= "background-color:red" > Apparel </div>
<div class= "Floor" style= "Background-color:orange" > Beauty </div>
<div class= "Floor" style= "Background-color:yellow" > Mobile </div>
<div class= "Floor" style= "Background-color:lightpink" > Home appliances </div>
<div class= "Floor" style= "Background-color:lightgreen" > Digital </div>
<div class= "Floor" style= "Background-color:green" > Sports </div>
<div class= "Floor" style= "Background-color:cyan" > Home </div>
<div class= "Floor" style= "Background-color:blue" > Maternity </div>
<div class= "Floor" style= "background-color:purple" > Food </div>
<div class= "Floor" style= "Background-color:lightseagreen" > Books </div>
<div class= "Floor" style= "background-color:lightcoral" > Services </div>
<div id= "Footer" > Tail </div>
</body>
jquery Floor Effect