开发者

jQuery Animate Effect not doing what its supposed to

开发者 https://www.devze.com 2022-12-21 13:29 出处:网络
The JS: var dialog = jQuery(\'#dialog\'); dialog.animate({ \'top\':\'-4px\', \'display\':\'toggle\' }, 300);

The JS:

var dialog = jQuery('#dialog');
dialog.animate({
  'top':'-4px',
  'display':'toggle'
}, 300);

The CSS:

#dialog {
  display: none;
  position: relative;
  width: 180px;
  height: auto;
  margin-left: -20px;
  top: -15px;
}

The Problem:

The animate executes and the div appears into view but after the animate is done executing it hides the div again but it remains in its new animated position. I know this because it appends the inline style="top:-4px" but the display inline style is gone after the animation executes.

The other problem is that this is a dialog window that has a cancel button so even if I add a callback of dialog.show(); after the animate completes. The cancel button does not work.

Cancel button animate:

dialog.animate({
    'top':'-15px',
    'display':'toggle'
}, 300);

This does nothing when the user clicks the cancel button. If i开发者_运维知识库 remove the callback from the first animate then the dialog window disappears and the user can't click cancel.

Am I missing something obvious here? I've used animate before and have never run into this problem.


Instead of 'display':'toggle' use 'show':'toggle'

This should fix both issues.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号