Move to DIV when switching using jQuery

I read and I'm trying to switch the screen to a div that is switching. It is located at the bottom of my site, so when you switch the contact form, you cannot say that it is, unless you scroll down.

I have this jQuery snippet that doesn't seem to work

//contact toggle $("#show-con").click(function(){ $("#contact-wrap").slideToggle("slow"); $("#contact-wrap").animate({scrollTop: $("#contact-wrap").offset().top}); }); 

The switch works fine, but it will not scroll to the div.

I read some old articles here, but, unfortunately, they are not related to sites that are no longer active.

+4
source share
2 answers

This will work, use html, body for your selector:

 $("#show-con").click(function(){ $("#contact-wrap").slideToggle("slow"); if ($("#contact-wrap").is(':visible')) { $("html, body").animate({scrollTop: $("#contact-wrap").offset().top}); } }); 

Also added check if the item is visible, and then scrolls differently.

+13
source

To determine this for all div that have a switch on them, refer to http://jsfiddle.net/LkTf8/79/ .

 $(document).ready(function() { $(".trigger").click(function(e){ var $toggled = $(this).attr('id'); var $paneltoggled = $(this).next(".panel").attr('id'); $(this).next(".panel").slideToggle('slow'); if ($("#" + $paneltoggled).is(':visible')) { $("html, body").animate({scrollTop: $("#" + $paneltoggled).offset().top});} }); }); 
+2
source

All Articles