当我滚动时,弹出应该在中心可见

时间:2017-01-27 10:50:20

标签: javascript html css

我的弹出窗口没有固定在中心..当我向下滚动时,它会向下滚动。即使我向下滚动,我希望它在中心可见..我的代码有什么问题..

$(window).scroll(function() { $rootScope.initPosition("previousOrdersPopupId")});


// set the popup position depending on scroll position
$rootScope.initPosition = function(id){

        var thePopup = $('#' + id).parent();
        $rootScope.myPopupId = id;
        var popupPosition = $(window.parent.document).scrollTop();
        if (popupPosition < 100) {
            popupPosition = 100;
        }
        var deltaPosition = (popupPosition + thePopup.height()) - ($(window).height() -20);

        // in case of truncated popup resize the iframe
        if(deltaPosition > 0 && id != "loadingPopupId"){
            contentResize(popupPosition + thePopup.height() + 20);
        }
        // set the horizontal scrollBar
        var scrollLeftPos = ($(window).width() - thePopup.width()) / 2;
        $(window).scrollLeft(scrollLeftPos);
        thePopup.css('position','fixed');
        //thePopup.css('top',250+ "px");




        //center of the page
       //thePopup.css('top', ( $(window).height() - thePopup.height() ) / 2 +$(window).scrollTop() + "px");

        if(id=='transitionPopupId' && deltaPosition > 0){
            thePopup.css('top',deltaPosition - 20);
        } else {
          thePopup.css('top',( $(window).height() - thePopup.height() ) / 2 +$(window).scrollTop() + "px");

        }


};

0 个答案:

没有答案