简体   繁体   English

IE10和11,jQuery动画的意外行为和溢出

[英]IE10 and 11, unexpected behaviour of jQuery animate and overflow

I used an animation which expands/collapses a form on an event. 我使用了一个在事件上展开/折叠表格的动画。 Works fine in FF, Chrome and Safari but IE10+ behaves unexpectedly and disturbs the alignment. 在FF,Chrome和Safari中可以正常工作,但IE10 +的行为异常并干扰对齐。

HTML: HTML:

<div id="w_oCExpandFormWrapper" style="position:absolute !important;">
    <div  class="w_oInput2" id="w_oCFirstField">
        <input type="hidden" id="w_oCRecomendTxt1"  />
    </div>
    <input id="w_oCRecommendArtficialButton" type="button" value="RECOMMEND"/>
    <textarea class="w_oInput3" id="w_oCRecomendTxt2" placeholder="...?"></textarea><br/>
    <div  class="w_oInput2" id="w_oCThirdField">
        <input type="hidden" id="w_oCRecomendTxt3" />
    </div>
    <input type="text" class="w_oInput2" id="w_oCRecomendTxt3" placeholder="..."/><br/>
    <input id="w_oCRecommendButton" type="button"  style="margin-left: 239px;" value="RECOMMEND"/>
</div>

JavaScript: JavaScript的:

to expand/collapse 展开/折叠

//Expand
$('#w_oHExpandFormWrapper').css({"height":"auto","overflow":"auto"})
//Collapse
$('#w_oHExpandFormWrapper').css({"height":"20px","overflow":"hidden"})

and for animation is. 对于动画来说。

$('#w_oHExpandFormWrapper').animate({"height":"20px","overflow":"hidden"},"fast");

Please help! 请帮忙!

This animation code is based on Animate element to auto height with jQuery . 此动画代码基于Animate元素,以使用jQuery自动调整高度 Press the Trigger button to cycle through the jQuery function calls that mutate the styles in the snippet. 按下“触发”按钮以循环遍历jQuery函数调用,这些函数会改变代码段中的样式。

Your form wrapper id is different in the html and js in the question. 您的表单包装ID在问题中的html和js中是不同的。 The auto height you had wasn't working in Chrome either, but after 5 years who knows if this is still an issue, but you just edited the question to add a character... 您以前的自动高度设置也无法在Chrome中使用,但是5年后,谁知道这仍然是一个问题,但是您只是编辑了问题以添加字符...

 let count = 0; $('#trigger').on('click', function() { if (count == 0) { //Expand console.log('expand'); $('#w_oHExpandFormWrapper').css({ "height": "auto", }); } else if (count == 1) { //Collapse console.log('collapse'); $('#w_oHExpandFormWrapper').css({ "height": "20px", }); } else if (count == 2) { //Expand Animation console.log('expand animation'); $('#w_oHExpandFormWrapper').animate({ "height": $( '#w_oHExpandFormWrapper' )[0].scrollHeight, }, "fast"); } else if (count == 3) { //Collapse Animation console.log('collapse animation'); $('#w_oHExpandFormWrapper').animate({ "height": "20px", }, "fast"); } count = (count + 1) % 4; }); 
 #w_oHExpandFormWrapper { background: red; top: 40px; min-width: 200px; overflow: hidden; height: 20px; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <button id="trigger">Trigger</button> <div id="w_oHExpandFormWrapper" style="position:absolute!important;"> <div class="w_oInput2" id="w_oCFirstField"> <input type="hidden" id="w_oCRecomendTxt1" /> </div> <input id="w_oCRecommendArtficialButton" type="button" value="RECOMMEND" /> <textarea class="w_oInput3" id="w_oCRecomendTxt2" placeholder="...?"></textarea><br/> <div class="w_oInput2" id="w_oCThirdField"> <input type="hidden" id="w_oCRecomendTxt3" /> </div> <input type="text" class="w_oInput2" id="w_oCRecomendTxt3" placeholder="..." /><br/> <input id="w_oCRecommendButton" type="button" style="margin-left: 239px;" value="RECOMMEND" /> </div> 

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

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