
[英]Create scroll to ID without jQuery and with offsetTop -80px
[英]Scroll 80px above id position instead of on id position
我有此代码段,该代码段在加载时滚动到页面上的#id
。 问题是我们的粘性导航高度为80px
,因此它覆盖了滚动到该特定#id
时我希望看到的部分。
这段代码很棒。 但我怎么让它在滚动80px的ID,而不是上面正好#id
。 (其wordpress网站)
jQuery(document).ready(function($){
if ( $(window).width() < 768){
if( $('body.woocommerce-page').length || $('body.single-product').length ){
$('html, body').animate({ scrollTop: $("#scrollto1").offset().top}, 1250);
}
}
});
谢谢你的帮助!
您可以从.offset().top
减去80。 见下文。
jQuery(document).ready(function($){
if ( $(window).width() < 768){
if( $('body.woocommerce-page').length || $('body.single-product').length ){
$('html, body').animate({ scrollTop: $("#scrollto1").offset().top - 80}, 1250);
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.