我在页面顶部有一个浮动导航栏,所以当我点击#ID链接时,它隐藏了我想要滚动到它后面的对象。
我使用jquery来滚动这段代码:
<script>
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
</script>是否有一种方法,我可以滚动到略低或高于标签的位置设置像素数量?
注意:确保允许chrome中的“不安全内容”,因为一些jquery不起作用。
发布于 2014-10-06 22:15:52
将scrollTop: target.offset().top更改为scrollTop: target.offset().top + x,其中x是要加或减的数字
发布于 2014-10-06 22:17:23
你是说
scrollTop: target.offset().top - 50https://stackoverflow.com/questions/26225703
复制相似问题