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