jQuery的scrollTop工程,但不会移动滚动条 [英] jquery scrollTop works but doesn't move the scrollbar

查看:452
本文介绍了jQuery的scrollTop工程,但不会移动滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过$ .load()函数加载DIV. 完成后,我执行$('#my_div').scrollTop(0);

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

它可以工作,内容从第一行可见,但是,这就是问题所在,从浏览器添加的左滚动条允许用户滚动div内容,但不会移动,而是停留在.scrollTop()之前的位置

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 !

是否有一种方法可以强制浏览器重新绘制div或执行某些操作以使滚动条滚动到顶部?

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

我试图从dom中删除div本身,添加正在加载"文本,然后在加载完成后重新创建,但是没有任何变化...

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...

我不在页面顶部滚动,这是一个模式(我正在使用Twitter引导程序)

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

这是我的模态

<!-- 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>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true"><?php echo Yii::t('General','close'); ?></button>
    </div>
</div>

这是JavaScript代码

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 );
            });

请注意:偶然地有效!

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

为什么?

推荐答案

尝试一下

$(document).scrollTop($('#my_div').offset().top);

这篇关于jQuery的scrollTop工程,但不会移动滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆