jQuery 工具:如何关闭叠加层?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3266780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 15:08:42  来源:igfitidea点击:

jQuery Tools: How to close an overlay?

jquerydialogpopupoverlayjquery-tools

提问by Rookian

$("a[rel]").getOverlay().close();
$("a[rel]").close();

Both don't work.

两者都不起作用。

$(document).ready(function () {
        $("a[rel]").overlay({
            mask: '#3B5872',
            effect: 'apple',
            onBeforeLoad: function () {
                var wrap = this.getOverlay().find(".contentWrap");
                wrap.load(this.getTrigger().attr("href"));
            },
            onLoad: function () {
                $('.contentWrap form').submit(function (event) {
                    event.preventDefault();
                    $("a[rel]").overlay().close();
                    hiHyman(this, update_employees, "html");
                });
            }
        });
    });

    function hiHyman(form, callback, format) {
        $.ajax({
            url: form.action,
            type: form.method,
            dataType: format,
            data: $(form).serialize(),
            success: callback
        });
    }

    function update_employees(result) {
        $("#gridcontainer").html(result);
    }

Any suggestions?

有什么建议?

I use Chrome because the onLoad event seems not work correctly in FF.

我使用 Chrome 是因为 onLoad 事件在 FF 中似乎无法正常工作。

回答by Nick Craver

Like this:

像这样:

$("a[rel]").overlay().close();

For most of their scripting you call the original method, e.g. .overlay()then call the method you wanton that object.

对于他们的大多数脚本,您调用原始方法,例如,.overlay()然后在该对象上调用您想要的方法

回答by serg

You need to set api:truein properties if you want to close it from js:

api:true如果要从 js 关闭它,则需要在属性中进行设置:

var overlay = $("a[rel]").overlay({
    ...
    api:true
});

overlay.close();

回答by coderazzi

The problem, in case of assigning the overlay to a class, is that there will be many overlay elements, so all must be closed:

问题是,如果将覆盖分配给一个类,将会有许多覆盖元素,因此必须关闭所有元素:

$.each($(".caddy_grid"), function(i, v){$(v).overlay().close();})

Alternatively, it is possible to simulate a click on the close button:

或者,可以模拟点击关闭按钮:

The class that triggers the overlay in my case is caddy_grid_overlay, so the close button can be accessed as:

在我的例子中触发覆盖的类是caddy_grid_overlay,所以可以通过以下方式访问关闭按钮:

$('.caddy_grid_overlay .close').click();

回答by Kowlown

Try

尝试

$("a[rel]").data("overlay").close();

I use this to close my overlays.

我用它来关闭我的叠加层。

source : http://forum.jquery.com/topic/having-trouble-timing-jquery-tools-overlay-to-close-after-a-few-seconds

来源:http: //forum.jquery.com/topic/have-trouble-timing-jquery-tools-overlay-to-close-after-a-few-seconds

回答by AndyTran2222

It will work for you, Please refer code here,

它将为您工作,请在此处参考代码,

var api = $("a[rel]").data("overlay");

api.close();//close this overlay

Reference :

参考 :

http://jquerytools.org/documentation/overlay/index.html#api

http://jquerytools.org/documentation/overlay/index.html#api

http://jquerytools.org/documentation/scripting.html

http://jquerytools.org/documentation/scripting.html

回答by fivefty

 $(document).ready(function() { 
    var overlayObject = $("a[rel]").overlay({ 
        top: 50,
        expose: {
                    color: '#232323',
                    closeOnClick: true
                },

                onClose:function() {   
                    $('#reg-login').hide();
                    $('#reg-register').hide();
                },
        effect: 'apple'
 });    

回答by Reza Shek

you can create a function and call it from anywher you want.

你可以创建一个函数并从任何你想要的地方调用它。

this function gonna work based on class name and a link.

这个函数将根据类名和链接工作。

function closeOverlay() { alert('aa'); var overlay = $(\"a.ShowOverlay\").overlay({ api:true });

    overlay.close();
}

函数 closeOverlay() { alert('aa'); var overlay = $(\"a.ShowOverlay\").overlay({ api:true });

    overlay.close();
}