刷新Html布局以重新计算滚动条 [英] Refresh Html layout to recalculate scrollbars

查看:288
本文介绍了刷新Html布局以重新计算滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 div ,其大小固定,显示滚动条,因为内容太大。还行吧。当我调整 div 的大小以隐藏滚动条时出现问题,我必须增加超过必要的大小隐藏滚动条。这是因为滚动条本身占用了 div 中的一些空间。有没有办法要求浏览器重新计算 div 的大小及其内部内容,看看是否真的应该有可滚动的内容?

I have a div with a fixed size which displays scrollbars because the content is too large. This is ok. My problem occurs when I resize the div in order to hide the scrollbars, I have to increase the size more than necessary to hide the scrollbars. This is because the scrollbars themselves occupy some space in the div. Is there a way to ask the browser to recalculate the size of the div and its inner content and see if there really should be a scrollable content or not?

推荐答案

使用jQuery进行DOM处理:

With jQuery for DOM handling:

$("div#yourdiv").attr("overflow", "hidden"); <-- remove scrollbars
setTimeout(function(){
   $("div#yourdiv").attr("overflow", "auto"); // auto | initial
},1); <-- 1 millisecond is enough to allow the DOM to update

这篇关于刷新Html布局以重新计算滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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