有人可以帮助我吗?
我有一个页面,其中有几个隐藏的部分和一系列链接到这些部分并显示它们的其他页面。最初,该页面直接跳转到锚点,但我将其改为从顶部滚动到该部分;问题是,在跳转到页面顶部并滚动之前,页面会短暂地跳转到锚点。
以下是我的代码:
function toggle(id) {
var element = document.getElementById(id);
var text = document.getElementById("arrow" + id);
if (element) {
var display = element.style.display;
if (display == "none" || display == '') {
element.style.display = "block";
text.innerHTML = "▲";
} else {
element.style.display = "none";
text.innerHTML = "▼";
}
}
};
jQuery(document).ready(function() {
jQuery(window.location.hash).show();
if (window.location.hash) {
setTimeout(function() {
jQuery('html, body').scrollTop(0,0).show();
jQuery('html, body').animate({
scrollTop: jQuery(window.location.hash).offset().top
-75}, 1000)
}, 0);
}
});
这里是一个页面:
<p><a href="http://204.128.208.7/automated-transfers-users/#inventoryPriceMaintenance">Effect on Auto-Transfers</a></p>
以下是链接页面的一部分内容:
<h4 class="blueToggle" onclick="toggle('inventoryPriceMaintenance')">An Incorrect Setting in Inventory Price Maintenance<a id="arrowinventoryPriceMaintenance">▼</a></h4>
<div id="inventoryPriceMaintenance" class="hiddencontent">
<p style="margin-left: 2em; margin-bottom: .3em;">Navigate to the back-screen</p>
<a href="http://204.128.208.7/wp-content/uploads/auto-transfer-7.png"><img class="aligncenter" src="http://204.128.208.7/wp-content/uploads/auto-transfer-7.png" alt="" width="85%" height="85%" /></a>
<p style="text-align: justify; margin-left: 2em; line-height: 1.5em; margin-bottom: .625em;">The item will not be included on automatically generated transfers to a store if the second character in the fourth column (<strong>COMP</strong>) is…</p>
<ul style="margin-left: 5em; line-height: 1.5em;">
<li><strong>D</strong> = discontinued (an item cannot be transferred to a store at which it is discontinued, but it can be transferred from that store)</li>
<li><strong>S</strong> = special order</li>
<li><strong>X</strong> = item has been discontinued everywhere (only relevant at store 00)</li>
</ul>
<p style="text-align: justify; margin-left: 2em;">An item will not auto-transfer if it is not authorized at the specific store</p>
<p style="text-align: justify; margin-left: 5em; line-height: 1.5em; margin-top: -1em; margin-bottom: 0px">Go to the back-screen and see if the store is on the list (a list of authorized stores can also be found on the Inventory Inquiry screen)</p>
<h4 class="blueToggle" onclick="toggle('inventoryPriceMaintenance')" style="margin-top: .3em">Hide -</h4>
</div>
我已经寻找了解决方案,并尝试了e.preventDefault();和return false,但都没有起作用,我不知道还有什么其他的尝试方法。
#thisAnchor
,但您只链接到.com#this
,然后JS执行类似于window.location.hash + "Anchor"
的操作以获取真正的锚点。这样浏览器就不会移动页面(#this
不存在),但是您的JS仍然可以移动到它,因为它知道要添加一致的最终部分。 - DBS