I have four links with href's pointing to URLs of pages that are loaded via .load()
, the problem is in IE the page jumps when you click it, i have attached a (window).scrollTo(0)
to the code and fixes it in all browsers besides IE.頁面跳轉點擊<a href> tag in IE, jquery is attached to the a href
I also have return false
on the code so it stops the default behaviour.
I have seen: Page jumps to the top onclick並試圖實現答案,但它似乎並不適用於我。
有誰知道解決方案嗎?
在href的:
<a href="welcome.html" name="welcome">Welcome</a>
<a href="about.html" name="about">About</a>
<a href="forum.html" name="forum">Forum</a>
<a href="contact.html" name="contact">Contact</a>
jQuery代碼:
$('#jqNav li a').click(function(e){
if($(this).parent().is(".nav1")){ $('.landing .main .nav ul').css({ "background-position" : "0 -50px" });}
else if($(this).parent().is(".nav2")) { $('.landing .main .nav ul').css({ "background-position" : "0 -100px" });}
else if($(this).parent().is(".nav3")) { $('.landing .main .nav ul').css({ "background-position" : "0 -150px" });}
else if($(this).parent().is(".nav4")) { $('.landing .main .nav ul').css({ "background-position" : "0 -200px" });};
stopAnim = true;
$page = $(this).attr('href');
var $hashTag = $(this).attr('name');
window.location.hash = $hashTag;
loadData();
$(window).scrollTop(0);
e.preventDefault();
});
那麼你在說什麼代碼? – Sparky
虐待添加到OP現在:) – Xavier
什麼在'loadData'?如果它是異步代碼,那可能是問題。 – lonesomeday