javascript - Hide one div, unhide another div, scroll to the new unhidden div -
i have function closegeneralhelp
takes 1 parameter: idtag
. function supposed following:
a) slideup
"help" div, b) slidedown
set of divs , c) scroll, jump, or otherwise go specific (but dynamically determined) other div of set of divs exposed via slidedown
.
i have 2 classes of divs ("divstoshow" , "divtohide"). "divstoshow" has few other divs contained in , each of divs has unique id
(this idtag
is).
parts (a) , (b) work fine. scrolling specific (but dynamically determined) div seems fail no matter try. here code. each /* */ comment block represents separate, failed (and flailing) attempt @ making work.
any on getting (c) work? javascript / jquery infant. reasonably related advice / pointers appreciated.
function closegeneralhelp(idtag){ $(".divstoshow").slidedown("slow"); $(".divtohide").slideup("slow"); /* var divid = document.getelementbyid(idtag); divid.style.display = 'block'; divid.scrollintoview(true); */ /* document.getelementbyid(idtag).scrollintoview();*/ /* $(window).scrollto(idtag,800,{queue:true});*/ /* window.location.hash = idtag;*/ /* window.settimeout(function() {window.scroll(0, findpos(idtag));}, 5);*/ }
thank you!
you need callback function, in case after slidedown done:
$(".divtohide").slideup("slow"); $(".divstoshow").slidedown("slow", function(){ var $showndiv = $(this); // callback of slidedown, after done, perform this: $('html,body').scrolltop( $showndiv.scrolltop() ); // or animated: $('html,body').animate({scrolltop: $showndiv.scrolltop()}, 1000); // in ms // or more native js document.getelementbyid( $(showndiv)[0].id ).scrollintoview(); });
if have old jquery , cant upgrade, might want discard $("#someelement").scrolltop()
in favor of $('#someelement').offset().top
Comments
Post a Comment