views:

171

answers:

2

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.

A: 

never seen display:toggle in css ... are you sure about it ?

luca
Yes, its a jQuery.animate feature. You can 'toggle' a property or use 'show' 'hide'Which works but then it goes back to being hidden after the event.
Mark
+1  A: 

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

This should fix both issues.

Nick Craver
This seemed to fix my first issue but does nothing for the second. It will move back up but not fade when you click cancel.My temporary solution that sort of works was to animate the opacity and set a callback that hides the element so you can click behind it.
Mark
@Mark - When I click cancel here, it animates up and goes away, are you using `'show':'toggle'` on cancel as well? Here's what I have: `$("#cancel").click(function() { dialog.animate({ 'top':'-15px', 'show':'toggle' }, 300); });`
Nick Craver
@Nick - I'll give it another shot. Maybe its something in the CSS or javascript else where thats causing an issue? Because I have done it the way you're saying before but for some reason it doesn't work in this instance. Very frustrating.
Mark