调整窗口滚动的位置

时间:2013-06-07 17:19:12

标签: jquery jquery-plugins

我有一个插件可以在页面上启动模式对话框。它位于中心,利用boxPosition(el)功能。

function boxPosition(el) {

    // calculate/set height of content area         
    var winH = $(window).height(),                          // viewport height
        winW = $(window).width(),                           // viewport width


    // position modal in center
    var boxH = $('#myModal').outerHeight(true),         // real modal height
        bmcH = ttlH + auxH + cntH + ftrH + 80,             // modal height plus content padding/margin  
        bmcW = $('#myModal').outerWidth(true),              // real modal width 
        bmcT = (winH - (boxH < bmcH ? boxH : bmcH)) / 2,   // top offset for centering          
        bmcL = (winW - bmcW) / 2;                          // left offset for centering 

    $('#myModal').css({ 'top': bmcT+'px', 'left': bmcL+'px' });
}

当我加载页面或调整页面大小时,在此插件中调用functioned:

boxPosition(el);

$(window).resize(function() {
    boxPosition(el);
});

我正在尝试解决另外两个问题:

  1. 我想让它集中在很多内容并且可以滚动的页面上。我试过这个,但似乎没有用。

    $(window).scroll(function(){     boxPosition(EL); });

  2. 我想在注册模式中的任何点击时调用该函数。

0 个答案:

没有答案