Can't get scrollIntoView to work
I'm trying to get JQuery's scrollIntoView to work on a page, but it doesn't seem to work. This is a simplified version of the page:
<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>
Whatever I do, I can't get this to work. I'm a beginner at JQuery, so I feel like there's a plethora of things I could be doing wrong here. I've also tried to pl开发者_如何学Pythonugin ScrollTo, of which the result should look a lot nicer, but it doesn't work either. What am I missing?
EDIT: It was suggested that the problem was that I used "#top" instead of ".top". I've updated this but it still doesn't work.
Hope this helps!!!
<!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>
#
indicates an ID, not a class. You want .top
and .bottom
.
精彩评论