var htmlTop = 0;
//获取右侧div高度,小编这里需要+300
var box1 = $('#main-box-1').offset().top + 300;
var box2 = $('#main-box-2').offset().top + 300;
var box3 = $('#main-box-3').offset().top + 300;
var box4 = $('#main-box-4').offset().top + 300;
//点击左边li菜单右边滑动到指定位置
$('.main-l li').click(function() {
let index = $(this).index();
if (index == 0) {
$('html, body').animate({
scrollTop: 0
}, 500)
} else if (index == 1) {
$('html, body').animate({
scrollTop: box1
}, 500)
} else if (index == 2) {
$('html, body').animate({
scrollTop: box2
}, 500)
} else if (index == 3) {
$('html, body').animate({
scrollTop: box3
}, 500)
} else if (index == 4) {
$('html, body').animate({
scrollTop: box4
}, 500)
}
})
//点击后删除原先li样式新增当前li样式
$(window).scroll(function(e){
htmlTop = $(window).scrollTop();
if(htmlTop == 0){
$(".main-l li").eq(0).addClass("active").siblings().removeClass("active");
}else if(htmlTop >= box1 && htmlTop < box2){
$(".main-l li").eq(1).addClass("active").siblings().removeClass("active");
}else if(htmlTop >= box2 && htmlTop < box3){
$(".main-l li").eq(2).addClass("active").siblings().removeClass("active");
}else if(htmlTop >= box3 && htmlTop < box4){
$(".main-l li").eq(3).addClass("active").siblings().removeClass("active");
}else if(htmlTop >= box4){
$(".main-l li").eq(4).addClass("active").siblings().removeClass("active");
}
});
PouchDB:一款基于JavaScript 的开源NoSQL文档数据库
JavaScript获取指定网站状态码查询代码(2种实现方法)
上面是“js点击左侧(头部)菜单栏右侧滑动到对应内容”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_11905.html
workflows工作流
水晶玉雕巨龙ComfyUI工作流
一位24岁的金发女海盗ComfyUI工作流
一只可爱的猫骑着一匹可爱的马ComfyUI工作流
雪地里一只可爱的小老虎
一位穿着优雅银色装饰黑色连衣裙的苗条模特
树上挂着一只快乐的荔枝ComfyUI工作流
一个港口配备了小型船只、起重机、集装箱和码头
一尊白玉猴王ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

利用js+css3做一个小鱼游泳特效
iframe开发admin后台
利用js做一个炫酷音乐背景效果
在线生成金属文字
jquery鼠标滑过图片边框特效(jquery.focus-follow插件)
css3搭积木叠加图形
HTML5 Canvas 刻度尺
css3实现星球旋转










