我在我的项目上使用了引导滚动间谍,基本上我有一个点击此处的链接,它有下面的url格式http://example.com/#positionA,在它加载的页面上有以下html代码
<p></p>
<h3 id="positionA">Position A</h3>
<p>This is a test code</p>我遇到的问题是页面加载到我想要的位置,但是滚动停止在
这是一个测试代码
位置代替A位置。
如何修复滚动间谍停止的位置,以便在段落标题之前停止并显示标题?谢谢
更新的项目是一个商店前的网站,我正在工作的条款和条件的网站。因此,在交付页面上,我有点击这里,如果客户点击它,它将带他到条款和条件页面上的特定部分。在身体上我有这个
<body id="cms" class="cms cms-3 cms-terms-and-conditions-of-use hide-right-column lang_en two-columns" data-spy="scroll" data-offset="50">所有的文本都指向这个部门
<div id="center_column" class="center_column col-xs-12 col-sm-9">
<div class="rte">
</div>
</div>因此,在传递页面上,我有以下代码
<li>Terms and conditions for delivery, refund and returns please <a href="http://examople.com/content/3-terms-and-conditions-of-use#refunds_returns">click here</a></li>发布于 2015-08-17 21:36:03
我已经找到了解决方案,下面是我的代码--如何修复它
var hash = false;
if(window.location.hash) {
hash = true;
}
if (hash)
{
hash = document.URL.substr(document.URL.indexOf('#')+1);
var anchor = $('#'+hash).offset();
console.log("left" + anchor.top);
anchor.top = anchor.top - 100;
console.log("top" + anchor.top);
$('html, body').animate({
scrollTop: anchor.top
}, 500);
}发布于 2015-08-13 20:33:23
使用涡旋间谍偏移量
通过添加
data-offset="10"至
<a data-spy="scroll" data-target="#positionA" data-offset="20" href="#positionA" >当计算滚动的位置时,它将“从顶部偏移”,以像素为单位。
https://stackoverflow.com/questions/31981523
复制相似问题