2011-10-05 136 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>