Search code examples
jqueryeffectstransferjquery-dialog

Jquery Making a dialog with transfer effect for reverse


i was looking for opening & closing jquery dialog with transfer effect and i got a good write up on this. when click on login button then dialog appear with transfer effect but i want when dialog should close then a reverse transfer effect should occur. my reverse transfer effect code is not working.

<!DOCTYPE html>
<html>
<head>
<link href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.min.css" rel="stylesheet" type="text/css" />
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>

<a id="fill-login-form" href="#">Login</a>

<div id="login-form" style="display: none; width: 340px; height: 135px;">
    Some stuff
</div>

</body>
</html>

$(document).ready(function() {

    // turn the div into a jQuery UI dialog and hide it
    var dlg = $('#login-form').dialog({
        title: 'Just a cool dialog',
        autoOpen: false,
        // hook to the 'beforeclose' event instead of 'close'
        beforeclose: function(event, ui) {
            dlg.dialog('widget').effect('transfer', {
                to: '#fill-login-form',
                className: 'ui-effects-transfer'
            }, 500, null);
            return true; // to close it
        }
    });

    // open the dialog when the link is clicked
    $('#fill-login-form').click(function() {
        //Hide your dialog here
        dlg.dialog("open").dialog("widget").css("visibility", "hidden");
         $(this).effect("transfer", {
      to: dlg.dialog("widget"),
      className: "ui-effects-transfer"
  }, 500, function() {
           //Open the dialog after showing your transfer effect
      dlg.dialog("widget").css("visibility", "visible");
  });
    });

});

enter link description here

please modify the code to get desired effect. thanks


Solution

  • For closing, to attribute recieves object, not id string. So it should be $("#fill-login-form") instead of #fill-login-form.

    For opening, your dlg assignment should be changed.

    Here's the code:

    http://jsfiddle.net/Lss3hcgg/1/