Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
93
rated 0 times [  95] [ 2]  / answers: 1 / hits: 16638  / 12 Years ago, tue, january 8, 2013, 12:00:00

I'm trying to make my browser window scroll down to the top of a div when clicked. The only problem is everything else works but that, the window should scroll down to the top of the div clicked...



So far I have:



$('.work-showcase').click(function(){
$('.work-showcase').animate({height:'135px'}, 500);
$(this).animate({height:'400px'}, 500);
$(window).scrollTop;
});


I've made a jsfiddle to show you what I mean...
http://jsfiddle.net/Jq4Vw/


More From » jquery

 Answers
7

I think you are trying to achieve this: http://jsfiddle.net/Jq4Vw/7/



$('.work-showcase').click(function(){
$('.work-showcase').animate({height:'135px'}, 500);
$(this).animate({height:'400px'}, 500).promise().done(function(){
$('html,body').animate({scrollTop: $(this).offset().top},500);
$(this).addClass('current').unbind('click'); // just add this line
});
});

[#81011] Monday, January 7, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
catrinas

Total Points: 587
Total Questions: 100
Total Answers: 105

Location: Rwanda
Member since Thu, Feb 10, 2022
2 Years ago
;