Javascript 切换来自按钮的动画

Javascript 切换来自按钮的动画,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有以下代码: $(function(){ $("#modal-launcher, #modal-background, #modal-close").click(function () { $("#modal-content,#modal-background").toggle("slow"); return false; }); }); 这个html: <button id='modal-launcher'> Launch Modal

我有以下代码:

$(function(){
    $("#modal-launcher, #modal-background, #modal-close").click(function () {
        $("#modal-content,#modal-background").toggle("slow");
    return false;
    });
});
这个html:

<button id='modal-launcher'>
  Launch Modal Window
</button>

<div id='modal-background'></div>

<div id='modal-content'>
  <button id='modal-close'>Close Modal Window</button>
</div>

启动模式窗口
关闭模式窗口
这是一个例子

现在,当您单击按钮时,模式显示在中间。相反,我希望有一个动画,其中模态似乎来自按钮“启动模态窗口”按钮,然后转到中心。这可能吗?我正在网上寻找一个例子,但我现在找不到,但我会继续寻找


这可能吗?谢谢你的帮助

我想这取决于你想在它上面投入多少工作,jQuery UI在这个场景中有一个默认效果,这个选项叫做“转移”,请在


如果jQuery UI不是一个选项,您可以使用按钮作为对话框的初始/最终位置,并设置对话框的不透明度、左侧和顶部属性的动画。

尝试以下操作:

$(function(){
        $("#modal-launcher, #modal-background, #modal-close").click(function () {
            $("#modal-content,#modal-background").show().animate({height: "10px", width: "10px"}, 500);
        return false;
        });
    });
    $(function(){
     $("#modal-launcher, #modal-background, #modal-close").click(function () {
         $("#modal-content,#modal-background").toggle(function(){
           $("#modal-content,#modal-background").animate({}, 1500 );
         });
         return false;
       });
    });

使用
设置动画
功能来产生效果。检查工作演示

有关
动画制作的更多信息,请单击此处:

检查演示:

尝试以下代码:

小提琴是

$(function(){
        $("#modal-launcher, #modal-background, #modal-close").click(function () {
            $("#modal-content,#modal-background").toggle(function() {
        $(this).animate({height: '800'});
    });
        return false;
        });
    });