web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 地图大全
  5. AIGC工具
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站
    手机应用

js点击左侧(头部)菜单栏右侧滑动到对应内容

473 ℃
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");
  }
});

PC端如何实现将网站添加到桌面的功能

javascript实现复制div文本内容(实测有效)

JavaScript获取指定网站状态码查询代码(2种实现方法)

JS获取当前电脑浏览器基本信息

盘点50个全面的正则表达式集合,从基本验证到高级匹配

标签: js切换 js滑动

上面是“js点击左侧(头部)菜单栏右侧滑动到对应内容”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_11905.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > js
本文共计1182个字,预计阅读时长8分钟

基金从业资格考试题库

一站式备考基金从业资格考试,收录2021-2025年模拟题库!呱呱工具箱

在线育儿补贴计算器

快来看看你到底可以领到多少补贴!

生活小工具

收录了万年历、老黄历、八字智能排盘等100+款小工具!生活小工具
上一篇: 推荐一款免费在线图片处理工具——佐糖图片平台
下一篇: 推荐一款优设网免费可商用字体——优设标题黑体
x 打工人ai神器