scrollto - Jquery SlideToggle AND scroll -


i'm having problem slidetoggle link appears @ bottom of page. want user click show/hide hidden div (which works fine)

the problem page doesn't scroll down show now, not hidden div

as jquery novice, there way toggle div , center on page? or @ least scroll down, without things getting complicated?

thanks

to perform function, i'd recommend using callback slidetoggle call set document scroll using scrolltop function. you'll able determine value scrolltop setter using offset top position of toggled container relative page. i'd suggest restricting scroll behavior fire when element shown, not hidden.

in general, directly setting page scroll can jarring ux. reason i'm going give code animates scrolltop rather straight sets using scrolltop function, approach not necessary direct call scrolltop equally position page. think user i'd rather see gradual scroll rather sudden positional change.

the code, instance, take form:

$(".myshowhidelink").click(function() {     $(".mytogglecontainer").slidetoggle("slow", function() {         if ($(this).is(":visible")) {             $(document).animate({                 scrolltop: $(this).offset().top             }, "slow")         }     }); }); 

you may want use $(this).offset().top - 50 or similar scroll's set few pixels above top of container, that's you. find don't elements butting against top border of window.

i apologize haven't created test case i'm shooting hip, if doesn't work advertised, let me know , i'll adjust code.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -