javascript - 使用javascript重定向的灯箱

标签 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) 去除掩码点击事件,然后弹出不会在外部点击时消失。

2) 制作一个显示弹出窗口的函数。

<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>

关于javascript - 使用javascript重定向的灯箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34151998/

相关文章:

javascript 检查结束日期是否大于或等于开始日期

javascript - RTCPeerConnection connectionState 从不从 "new"移动到 "checking"/"connected"

javascript - HTML 按钮不会运行功能

javascript - 使用 Javascript/Node.js 重新采样时间序列或数据帧

javascript - 更新函数 javascript 和 mongodb

javascript - 用函数交换 img src (JavaScript)

html - Css 定位和照片大小调整

jquery - 悬停时用边框为列表项下划线

javascript - 使用动态值的 Jquery 点击函数

javascript - angular,访问 ng-view 包装 div 之外的范围