Reputation: 353
<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).
Upvotes: 1
Views: 2219
Reputation: 9561
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>
Upvotes: 3
Reputation: 736
scrollLeft
and scrollTop
is the correct way but you can add animation and dynamic values for a better flexibility: https://jsfiddle.net/twey5d7u/
Upvotes: 2
Reputation: 353
I found a solution:
$(MainDiv).scrollLeft(DivInsideWidth);
$(MainDiv).scrollTop(0);
Upvotes: 1