<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./js/jquery.min.js"></script>
<style>
.recommend {
height: 1000px;
background-color: red;
}
.fixedtool {
width: 100px;
height: 101px;
background-color: pink;
}
.jiadian {
width: 300px;
height: 200px;
background-color: salmon;
}
.shouji {
width: 300px;
height: 200px;
background-color: salmon;
}
.current {
background-color: black;
}
</style>
</head>
<body>
<div class="recommend">1</div>
<div class="fixedtool">
<ul>
<li class="current">家电</li>
<li>手机</li>
</ul>
</div>
<div class="floor ">
<div class="jiadian w">家电</div>
<div class="shouji w">手机</div>
</div>
<div class="jiadian">
</div>
<script>
$(function() {
function toggleTool() {
if ($(document).scrollTop() >= toolTop) {
$(".fixedtool").fadeIn();
} else {
$(".fixedtool").fadeOut();
};
}
var toolTop = $(".recommend").offset().top;
toggleTool();
$(window).scroll(function() {
toggleTool();
});
//点击导航栏得到相应内容
$(".fixedtool li").click(function() {
//每次点击li去往页面要去的位置
//选出索引号的值去除他的位置
console.log($(this).index());
var current = $(".floor .w").eq($(this).index()).offset().top;
//页面滚动效果
$("body,html").stop().animate({
scrollTop: current
});
//点击之后添加current
$(this).addClass("current").siblings().removeClass();
})
})
</script>
</body>
</html>
标签:jquery,function,fixedtool,color,height,current,73,background,bug From: https://blog.51cto.com/u_15460007/6048618