there is a button <button id="cb-btn" data-toggle="collapse" data-target="#cb">Кнопка</button> that opens / closes the block <div id="cb" class="row collapse"><!-- Содержимое --></div> . How to write a script that, when a block is expanded, would scroll down to the block size? For example, $("#cb-btn").click(function(){if($(#cb раскрылся) прокрутить вниз на его высоту}) ?
|
1 answer
In the code that opens the block, add:
$('html, body').scrollTop($('body').scrollTop()+height); If you want to make a smooth scrolling animation:
$('html, body').animate({ scrollTop: $('body').scrollTop()+height }, 1000); However, you need to know the block size (height). If it is fixed or it does not matter in principle, then set in numbers. If not, then 2 options:
- Wait for the completion of the block disclosure animation.
- Find out the size of an element using the plugin: http://dreamerslab.com/blog/en/get-hidden-elements-width-and-height-with-jquery/
- Used bootstrap, respectively collapse bootstrap, trying to understand where you can insert this line, but did not understand. I would like to write a separate script that would process
$(#cb-btn).click(function(){if(div раскрывается) прокрутка вниз на n пикселей})- rival.dm
|