jQuery slideToggle() peculiar behaviour in Chrome/Safari

感情迁移 提交于 2019-12-11 08:17:42

问题


I am having a problem in Chrome when I slideToggle() and element.

EDIT: Example here, click Link A a few times and you'll see what I mean.

The HTML is along the lines of:

<div>
    <a>Link A</a>
    <a id="myLink">Link B</a>
</div>

With very simple CSS floating all the links to the left horizontally:

a{
  float: left;
  margin-right: 20px;
  height: 20px;
  width: 20px;
}

#myLink{
   display: none; 
}

The JavaScript simply toggles between showing myLink and hiding it on some event.

$('#myLink').slideToggle();

When slideToggle() is called the first time, everything works nicely; the link appears horizontally aligned with the other link. However, if I hide it again, when it reappears in Chrome/Safari the link appears underneath the other link (instead of alongside it). Also, I've noticed if I use the Developer Tools in Chrome and click on the element, it fixes itself and moves the link to be horizontally inline with the other link.

Anyone know of any issues with slideToggle() in WebKit?


回答1:


Don't float DIV or you can give it a width in pixels.



来源:https://stackoverflow.com/questions/9569148/jquery-slidetoggle-peculiar-behaviour-in-chrome-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!