jquery - How can I force browser to follow a div which is going to be shown? -


a <div> or <pre> on bottom of page, going toggled/shown by:

$(document).ready(function(){   $("#slice_img").click(function(){     $("#slice_pre").slidetoggle("slow");   }); }); 

and text appeared on bottom.

how can automatically chase , follow text going shown browser user, himself, won't need scroll down see newly-appeared text?

  • i don't want scroll down end of page! want browser follow exact text, while slide down in order appeared.

you may (!) understand better picture. enter image description here

something along these lines should work (if understand correctly):

demo

$(document).ready(function(){   $("#slice_img").click(function(){     $("#slice_pre").slidetoggle("slow", function() { // add callback function slidetoggle         $('html, body').animate({             scrolltop: $("#slice_pre").offset().top         }, 1000);     });   }); }); 

though should using classes instead of id's make reusable. code become:

$(document).ready(function(){   $(".slice_img").click(function(){     $(".slice_pre", $(this)).slidetoggle("slow", function() {         $('html, body').animate({             scrolltop: $(this).offset().top         }, 1000);     });   }); }); 

demo


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -