打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
关于滚动条滚动到指定位置触发jq事件和html锚点



html代码:

   <div class="div_md" style="height: 38px;background: pink;">
<a href="#a">点击我就会跳到第一段</a>
<a href="#b">点击我就会跳到第二段</a>
<a href="#c">点击我就会跳到第三段</a>
   </div>

<h2 id="a" style="width:200px;height: 400px;background: red;">我是标题一</h2>
<h2 id="b" style="width:200px;height: 400px;background: pink;">我是标题二</h2>

<h2 id="c" style="width:200px;height: 300px;background: green;">我是标题三</h2>


jq代码:

$(function() {
$(".div_md a").click(function() {
$("html, body").animate({
scrollTop: $($(this).attr("href")).offset().top - 100 + "px"
}, 1500);
return false;
});
//滚动条滚动到指定位置触发下面事件
var getDiv_md = $(".div_md");
var offSet = getDiv_md.offset().top;
$(window).scroll(function(){
if ($(window).scrollTop() > offSet){
$(".div_md").css({"position":"fixed","left":"10px","top":"10px","z-index":"2"});
}else{
$(".div_md").css({"position":"","left":"0px","top":"","z-index":""});
}
})
});


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
快速入门LXUI基于Boostrap V3.1改造而来
用flex布局实现栅格系统
Bootstrap每天必学之栅格系统(布局)
怎么用jquery定位一个div在某个input附近
8. 绝对定位失效(亲测)
css 宽度(CSS width)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服