简体   繁体   中英

Function to move scroll to the right-top corner of DIV in jQuery

 <div style=width:200px;height:200px;border-style:solid;overflow:scroll;> <div style=width:500px;height:500px;> Text, something </div> </div> 

This is example html code. I need to move view (Scroll) of div to right-top on event (For example on button click).

scrollLeftscrollTop是正确的方法,但是您可以添加动画和动态值以获得更好的灵活性: https : //jsfiddle.net/twey5d7u/

Try jQuery .scrollLeft() . Here is the working code.

 $(function() { $('#scroll').click(function() { var $scroll = $('.scrollthis'); $scroll.parent().scrollLeft($scroll.width()); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div style="width:200px; height:150px; border-style:solid; overflow:scroll;"> <div class="scrollthis" style="width:500px; height:500px;"> Text, something </div> </div> <button id="scroll">Scroll</button> 

I found a solution:

$(MainDiv).scrollLeft(DivInsideWidth);
$(MainDiv).scrollTop(0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM