简体   繁体   English

在div单击上显示和隐藏弹出窗口

[英]Show and hide a popup on div click

I am working on a small website and have some divs arranged in the layout on the click of which I have to show a modal window by animation. 我正在一个小型网站上工作,单击时必须在布局中安排一些divs ,我必须通过动画来显示modal window

After it has appeared, when the user pressed Esc , the modal window has to close and should open again with the same effect if the button is clicked again. 出现之后,当用户按下Esc ,模态窗口必须关闭,并且如果再次单击该按钮,则应再次打开,效果相同。

Here's how my code looks like: JSFIDDLE 我的代码如下所示: JSFIDDLE

For me, the div appears first time (not appearing in this fiddle though somehow), and on clicking on it the next time, it just makes it's display visible (the animation doesn't repeat again). 对我而言,div第一次出现(尽管不知何故不在此小提琴中出现),而下次单击它时,它只是使其显示可见(动画不再重复)。 It would be great if somebody could point out what I am missing here or what's wrong in the above code. 如果有人可以指出我在这里缺少什么或上面的代码有什么问题,那就太好了。

Solution: http://jsfiddle.net/JMU8A/1/ 解决方案: http : //jsfiddle.net/JMU8A/1/

$(document).on("keydown", function (event) {
    if (event.keyCode === 27) {
        $(".modal-mask").css("display", "");
        $(".modal-popup").css({
            "display": "",
            "width": "",
            "height": "",
            "top": "",
            "left": ""
        });
    }
});

Not sure if this is what you wanted but here you go 不确定这是否是您想要的,但是您去了

$(function () {
    $(".bigbutton").on("click", function () {
        $(".modal-mask, .modal-popup").fadeIn();
        $(".modal-popup").animate({
            width: '80%',
            left: '10%'
        }, 'slow', function () {
            $(".modal-popup").animate({
                'height': '80%',
                    'top': '10%'
            }, 200, "swing", function () {});
        });
    });
    $(document).on("keydown", function (event) {
        if (event.keyCode === 27) {
            $(".modal-popup").animate({
                width: '5%',
                left: '50%'
            }, 'slow', function () {
                $(".modal-mask, .modal-popup").fadeOut();
            });
        }
    });
});

FIDDLE 小提琴

Notes to your animate() parameters. 有关animate()参数的注释。 Slow already means that the duration is 200 so you don't have to pass that again. Slow已经意味着持续时间为200,因此您无需再次通过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM