2011-10-05 135 views
0

我想让JQuery的scrollIntoView在页面上工作,但它似乎不工作。这是该页面的简化版本:无法让scrollIntoView工作

<html> 
<head> 


    <script type="text/javascript" src="Scripts/jquery-1.6.4.min.js"></script> 

    <script type="text/javascript"> 
$('.top').click(function() { 
    $('.bottom')[0].scrollIntoView(); 
}); 

</script> 
</head> 
<body> 
<div><a href ="#" class= "top">Hello</a></div> 
<div style = "margin-top: 1000px"class = "bottom">hello</div> 
</body> 
</html> 

无论我做什么,我都无法得到这个工作。我是JQuery的初学者,所以我觉得在这里我可能做的错误太多了。我也尝试插入ScrollTo,其结果应该看起来好很多,但它也不起作用。我错过了什么?

编辑:有人建议,问题是我用“#top”而不是“.top”。我已经更新了这个,但它仍然不起作用。

回答

0

#表示一个ID,而不是一个类。你需要.top.bottom

+0

我已经这样做了,但我没有帮助任何东西......任何其他想法? – HankSmackHood

1

希望这有助于!

<!doctype html> 
<html> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> 
<script src="/jquery.scrollintoview.js"></script> 
$(document).ready(function(){ 
$("a.top").click(function(){ 
$("div:last").scrollintoview(); 
}); 
}); 
</script> 
</head> 
<body> 
<div><a href ="#" class="top">Hello</a></div> 
<div style = "margin-top: 1000px" class ="bottom">hello</div> 
</body> 
</html>