realtebo realtebo - 1 year ago 95
jQuery Question

jquery scrollTop works but doesn't move the scrollbar

I'm having a DIV loaded via $.load() function.
On complete, I execute $('#my_div').scrollTop(0);

It works, the content is visible from first line, but, and this is the problem, the left scrollbar, added from browser to allow user to scroll div content, is not moved, it stay where was before .scrollTop().

So if my user manually scroll down to bottom, then ask for data refresh, the data will be refreshed, and the content will be visible from first line, but scrollbar remain at bottom, so if the user clicks, the content will be scrolled down to bottom !

Is there a way to force browser to redraw the div or something to do to have even the scrollbar scrolled to top ?

EDIT 1: I tried to remove the div itself from the dom, add a 'loading' text, then recreate again after load is complete, but nothing changes...

EDIT 2: i'm NOT scrolling at the top of the page, it's a modal (i'm using twitter bootstrap)

EDIT 3: this is my modal

<!-- Modal di verifica duplicati -->
<div id="fullDataModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="fullDataModal" aria-hidden="true">
<div class="modal-body">
<i class="icon-spinner icon-spin"></i>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><?php echo Yii::t('General','close'); ?></button>

And this is javascript code

$("DIV#fullDataModal DIV.modal-body")
.load ("'. $this->createUrl("view", array("ajax" => true, "id" => $model->id)) .'"+contact_id, function(){
$("DIV.modal-body").scrollTop( 0 );

Please note: accidentally this works !

$("DIV.modal-body").scrollTop( 1 );

Why ?

Answer Source

try this

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download