Position simplemodal modal on top of an existing div

六眼飞鱼酱① 提交于 2019-12-08 12:50:46

问题


I'm trying to position a modal dialog on top of an existing div, using simplemodal plugin.

Here's my code; it's not working:

jQuery(function ($) {

    $('.slider-caption .basic').click(function (e) {

        var p = $("#slider1");
        var position = p.position();

        $('#basic-modal-content').modal({
            position: "absolute",
            left: position.left,
            top: position.top
        });

        return false;
    });
});

It's still drawing in the middle of the window. I've also tried to set autoPosition option to false, but that just makes it draw below the existing content at the left.

I'm using version 1.4.1 of simplemodal.


回答1:


Here's what I did to get it to work:

jQuery(function ($) {
    $('.slider-caption .basic').click(function (e) {

        var position = $("#slider1").offset();

        $('#basic-modal-content').modal({
            appendTo: "#slider1",
            autoPosition: false,
            position: "absolute",
            left: position.left,
            top: position.top
        });

        return false;
    });
});



回答2:


Actually there's extraneous stuff in there. it's just the appendTo which does it, really nice:

jQuery(function ($) {
    $('.slider-caption .basic').click(function (e) {

        $('#basic-modal-content').modal({appendTo:"#slider1", autoPosition: false,});

        return false;
    });
});


来源:https://stackoverflow.com/questions/4160138/position-simplemodal-modal-on-top-of-an-existing-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!