简体   繁体   English

jQuery CSS渲染 - 适用于Firefox,而不适用于Chrome

[英]jQuery CSS rendering - works in Firefox, not in Chrome

I'm using a jQuery slider to adjust the padding of a DIV containing paragraph text. 我正在使用jQuery滑块来调整包含段落文本的DIV的填充。 As I increase the padding on all sides equally, it should force the enclosed paragraphs into an ever-narrower column, in the center of the page. 当我平均增加所有边的填充时,它应该将封闭的段落强制到页面中心的更窄的列中。

This works in Firefox, but in Chrome the paragraph widths remain constant (ie they don't become narrower as the DIV's padding pushes in on them), so pushing the layout to the right. 这适用于Firefox,但在Chrome中,段落宽度保持不变(即它们不会随着DIV的填充推入它们而变窄),因此将布局推向右侧。

I've recreated the issue here: jsfiddle.net/ms3Jd . 我在这里重新创建了这个问题: jsfiddle.net/ms3Jd You can try it in Chrome and Firefox to see the difference. 您可以在Chrome和Firefox中试用它来查看差异。

Any ideas on how to force Chrome to refresh the enclosed paragraphs? 有关如何强制Chrome刷新所附段落的任何想法?

I know there are ways to force (or trick) Chrome to refresh/redraw/recalcuate the page elements, but don't know how to do it. 我知道有办法强制(或欺骗)Chrome刷新/重绘/重新计算页面元素,但不知道如何操作。 Any ideas? 有任何想法吗?

Taken from here: How can I force WebKit to redraw/repaint to propagate style changes? 从这里开始: 如何强制WebKit重绘/重绘以传播样式更改?

sel.style.display='none';
sel.offsetHeight; // no need to store this anywhere, the reference is enough
sel.style.display='block';

I quickly applied it here, but you should make it into a function: http://jsfiddle.net/thirtydot/ms3Jd/5/ 我在这里快速应用它,但你应该把它变成一个函数: http//jsfiddle.net/thirtydot/ms3Jd/5/

I'm using fadeTo to force chrome to refresh. 我正在使用fadeTo强制刷新铬。
Not sure but I guess it's the animate on fadeTo that does the trick 不确定,但我猜这是fadeTo上的动画制作技巧
try that line on jsfiddle . jsfiddle上尝试该行。

$('#preview > div').css('padding', ui.value + '%' ).children('p').fadeTo(1, .99).fadeTo(1, 1);

You can add the overflow and float properties: 您可以添加overflow和float属性:

#preview > div {
    padding: 5%;
    overflow: auto;
    float: left;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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