更改简单的内联模态窗口css脚本

时间:2012-08-03 19:25:24

标签: jquery css

我正在使用sohtanaka.com的'简单内联模式窗口css'脚本。由于这个网站离线,我现在找不到我的答案。

有人能帮助我吗?

我想在页面加载时只显示一次弹出窗口,而不是一直显示。

包含弹出窗口的Div:

<div id="popup_load" class="popup_block">
<b>Lorem ipsum dolores sit amet</b>
</div>

脚本

<script type="text/javascript">
$(document).ready(function(){

    $.fn.popOpen = function(){

        var popID = $(this).attr('rel'); //Get Popup Name
        var popURL = $(this).attr('href'); //Get Popup href to define size

        //Pull Query & Variables from href URL
        var query= popURL.split('?');
        var dim= query[1].split('&');
        var popWidth = dim[0].split('=')[1]; //Gets the first query string value


        //Fade in the Popup and add close button
        $('#' + popID).fadeIn('slow').css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="images/close.png" class="btn_close" title="<?php echo $lang['sluit'] ?>" /></a>');

        //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
        var popMargTop = ($('#' + popID).height() + 20) / 2;
        var popMargLeft = ($('#' + popID).width() + 20) / 2;

        //Apply Margin to Popup
        $('#' + popID).css({
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
        });

        //Fade in Background
        $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
        $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies
    };

    $('a.poplight[href=#?w=400]').popOpen(); //Run popOpen function once on load

    //Close Popups and Fade Layer
    //$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('a.close').live('click', function() { //When clicking on the close...
        $('#fade , .popup_block').fadeOut(function() {
            $('#fade, a.close').remove();  //fade them both out
            location.reload(); // reload page
        });
        return false;
    });

    popOpen
});
</script>

2 个答案:

答案 0 :(得分:0)

首次显示弹出窗口时设置cookie。然后在再次显示之前,在显示之前检查cookie是否存在。

$(document).ready(function(){
    if (cookie is set){
        return ;
    }

    show cookie code

    then mark cookie as set
});

答案 1 :(得分:0)

点击实际链接关闭弹出窗口,可能包含一个#符号作为href,这会导致浏览器重新加载页面。尝试使用这样的功能来关闭功能

$('a.close').live('click', function(e) { //When clicking on the close...
        e.preventDefault();
        $('#fade , .popup_block').fadeOut(function() {
            $('#fade, a.close').remove();  //fade them both out
            location.reload(); // reload page
        });
        return false;
    });

这可以防止链接执行默认操作,并且会导致弹出窗口仅在加载时显示一次