使用javascript进行重定向的灯箱

时间:2015-12-08 09:16:07

标签: javascript jquery html css

我打算在印地文启动我的网站,我计划在网站打开时,灯箱应该要求选择语言并相应地重定向。我使用以下代码:

<html>
<title>Test</title>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
$(document).ready(function() {  
    var id = '#dialog';

    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    $('#mask').css({'width':maskWidth,'height':maskHeight});

    //transition effect
    $('#mask').fadeIn(500); 
    $('#mask').fadeTo("slow",0.9);  

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    //Set the popup window to center
    $(id).css('top',  winH/2-$(id).height()/2);
    $(id).css('left', winW/2-$(id).width()/2);

    //transition effect
    $(id).fadeIn(2000);     

    //if close button is clicked
    $('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask').hide();
        $('.window').hide();
    });

    //if mask is clicked
    $('#mask').click(function () {
        $(this).hide();
        $('.window').hide();
    });
});
</script>

<style>
#mask {
position: absolute;
left: 0;
top: 0;
z-index: 9000;
background-color: #000;
display: none;
}

#boxes .window {
position: absolute;
left: 0;
top: 0;
width: 440px;
height: 200px;
display: none;
z-index: 9999;
padding: 20px;
border-radius: 15px;
text-align: center;
}

#boxes #dialog {
width: 720px;
height: 320px;
padding: 10px;
background-color: #ffffff;
font-family: Helvetica, 'Segoe UI Light', sans-serif;
font-size: 15pt;
}

#popupfoot {
font-size: 11pt;
position: absolute;
bottom: 0px;
width: 250px;
left: 250px;
padding-bottom:5px;
}
</style>
</head>

<body><div id="boxes">
<div id="dialog" class="window">
<h1>CHOOSE YOUR LANGUAGE</h1>
<a href="http://www.vashikaranguruji.com" target="_blank"><h2>ENGLISH            </h2></a>
<a href="http://www.vashikaranguruji.com/h" target="_blank"><h2>HINDI</h2></a>
<div id="popupfoot"><a href="#" class="close agree">Close</a></div>
</div>
<div id="mask"></div>
</div>
<div>
<h1> This is hidden Part </h1>
</div>

</body>
</html>
  1. 这对我来说很好,但是当我在灯箱外面点击时,灯箱会消失。我想要如果我点击灯箱外面,它不应该消失。我该怎么办?
  2. 其次我想点击一个按钮来改变语言,应该再次打开这个对话框。我不知道该怎么做。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

1)删除掩码点击事件,然后弹出窗口不会在外部点击时消失。

2)为show popup创建一个函数。

<script>

function showLanguageSelectionModal(){
var id = '#dialog';

//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();

//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});

//transition effect
$('#mask').fadeIn(500); 
$('#mask').fadeTo("slow",0.9);  

//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();

//Set the popup window to center
$(id).css('top',  winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);

//transition effect
$(id).fadeIn(2000);   
}


$(document).ready(function() {  
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();

$('#mask').hide();
$('.window').hide();
});

 showLanguageSelectionModal();

});
</script>

HTML

<button onclick="showLanguageSelectionModal();">Select Language</button>