在计算机Jquery中使用其他函数时,循环更改的时间(Timing for loop changes when using other functions in the computer Jquery)
我在这个JSFiddle中有一个脉冲动画
当你自己使用它时,它工作得很好。 我遇到的问题是当我开始浏览网页,打开iTunes或者当窗口仍然打开时你会做的其他事情,脉冲的时间开始波动。
脉冲的功能是这样的:
function fadeItIn() { window.setInterval(function(){ // Fade Ins $('#child4,#child4C').fadeIn(175); setTimeout(function () { $('#child3,#child3C').fadeIn(175); }, 175); setTimeout(function () { $('#child2,#child2C').fadeIn(175); }, 350); setTimeout(function () { $('#child1,#child1C').fadeIn(175); }, 525); setTimeout(function () { $('#child,#childC').fadeIn(175); }, 700); // Fade Outs setTimeout(function () { $('#child,#childC').fadeOut(175); }, 875); setTimeout(function () { $('#child1,#child1C').fadeOut(175); }, 1050); setTimeout(function () { $('#child2,#child2C').fadeOut(175); }, 1225); setTimeout(function () { $('#child3,#child3C').fadeOut(175); }, 1400); setTimeout(function () { $('#child4,#child4C').fadeOut(175); }, 1575); }, 3000); };
我觉得问题发生在函数内的3秒间隔期间。 我需要脉冲重复,所以我需要它在那里。
您认为导致此问题的原因是什么?我该如何解决?
I have a pulsing animation in this JSFiddle
When you use it on its own, it works just fine. The problem I'm having is when I start browsing the web, open iTunes or whatever else you would do while that window is still open, the timings of the pulses start to fluctuate.
The function for the pulses is this:
function fadeItIn() { window.setInterval(function(){ // Fade Ins $('#child4,#child4C').fadeIn(175); setTimeout(function () { $('#child3,#child3C').fadeIn(175); }, 175); setTimeout(function () { $('#child2,#child2C').fadeIn(175); }, 350); setTimeout(function () { $('#child1,#child1C').fadeIn(175); }, 525); setTimeout(function () { $('#child,#childC').fadeIn(175); }, 700); // Fade Outs setTimeout(function () { $('#child,#childC').fadeOut(175); }, 875); setTimeout(function () { $('#child1,#child1C').fadeOut(175); }, 1050); setTimeout(function () { $('#child2,#child2C').fadeOut(175); }, 1225); setTimeout(function () { $('#child3,#child3C').fadeOut(175); }, 1400); setTimeout(function () { $('#child4,#child4C').fadeOut(175); }, 1575); }, 3000); };
I feel like the issue is happening during the 3 second interval within the function. I need the pulses to repeat, so I need it in there.
What do you all think is causing this problem and how can I fix it?
原文:https://stackoverflow.com/questions/18326772
最满意答案
您可以使用Flexbox,只需在父元素上设置
display: flex
,在右元素上设置flex-shrink: 0
。.parent { width: 400px; height: 200px; display: flex; } .left { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; background: red; } .right { background: lightblue; flex-shrink: 0; }
<div class='parent'> <div class='left'> This div should display all text content possible without line-breaking and display '...' where its being cut </div> <div class='right'> This div is as wide as its text content </div> </div>
You can use Flexbox for this, just set
display: flex
on parent andflex-shrink: 0
on right element..parent { width: 400px; height: 200px; display: flex; } .left { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; background: red; } .right { background: lightblue; flex-shrink: 0; }
<div class='parent'> <div class='left'> This div should display all text content possible without line-breaking and display '...' where its being cut </div> <div class='right'> This div is as wide as its text content </div> </div>
相关问答
更多-
你是这个意思吗?
-
width:50px; 需要放在divUserContCon中。 你不能依靠auto来占用任何子div的宽度。 width:50px; Needs to be put in divUserContCon. You can't rely on auto to only take up the width of any child divs.
-
这是一种简单的方法。 由于您知道父级和前两个子元素的高度,因此可以对第三个子块使用绝对定位: .A { width: 100%; } .parent { height: 300px; width: 300px; position: relative; } .a1 { height: 100px; background-color: pink; } .a2 { height: 100px; background-color: beige; } . ...
-
仅限现代浏览器: HTML:12345678
-
当div大于其父级时,如何将div扩展到其内容宽度?(How to expand a div to its content width WHEN it is larger than its parent?)[2022-10-19]
你可以使用display: inline-block; 在#content-div上 You can use display: inline-block; on the #content-div -
您可以使用Flexbox,只需在父元素上设置display: flex ,在右元素上设置flex-shrink: 0 。 .parent { width: 400px; height: 200px; display: flex; } .left { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; background: red; } .right { background: ...
-
添加white-space: nowrap到父div并为子节点添加display: inline-block而不是float: left ,例如: .parent_div { white-space: nowrap; } .parent_div > div { display: inline-block; } 这是一个例子: FIDDLE Add white-space: nowrap to the parent div and for the children add display: ...
-
经过一些咨询后我找到了解决方法/答案。 诀窍是威胁表格和表格行等div。 添加一些额外的样式后,对话框看起来应该是应该的。 https://jsfiddle.net/qfqjq82r/7/ 和CSS: #location-picker .modal-content { display: table; width: 100%; } #location-picker .modal-dialog{ width: 80%; height: 85%; } #location-pic ...
-
div中的绝对定位div占用所有剩余空间(Absolute-positioned div within a div that takes all remaining space)[2022-08-04]
在.sidebar, .mapcontainer, .container规则中使用视口单位vh * { box-sizing: border-box; } html, body { margin: 0; } .sidebar, .mapcontainer, .container { height: 100vh; } .container { border: 1px solid; display: flex } .sidebar { width: ... -
你可以尝试这样: DEMO CSS: .more-info-dropdown-div-label { background: #fafafa; padding: 4px 10px 4px 10px; margin: 0 auto; font-size: 20px; -webkit-border-radius: 0 0 50px 50px; border-radius: 0 0 50px 50px; ...