Click me :-)

jQuery .animate() sets display:none, how to avoid?

I have the following code: HTML:
Click me :-)
Stay, damn!
JavaScript: $('#clickme').click(function() { $('#info').animate({ marginBottom: 'toggle' },{ duration:500 }); }); It's also available at http://jsfiddle.net/DxnQJ/ Obviously, I want the `#info DIV` to appear/disappear whenever the `#clickme DIV` is clicked. It's working as intended, except that the `#info DIV` disappears after the animation due to jQuery setting its CSS `display` property to `none`. How can I tell jQuery to stop hiding my `DIV`?
Checking out jQuery source, it looks like 'toggle' was designed for effects that are either entirely shown or hidden (like height, width, and opacity). What happens is that clicking 'Click me :-)' and animating something not hidden for the first time has the same effect as if you had marginBottom: 'hide'. So when it is done animating, jQuery( elem ).hide(); is called on your element.

以上就是jQuery .animate() sets display:none, how to avoid?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏