【发布时间】:2021-12-18 08:05:40
【问题描述】:
我现在在一个网站上工作,我必须为几个页面创建一个退出弹出窗口。我已经创建了弹出窗口,但它的背景保持活跃。所以发生的事情是,当我对其进行测试时,一旦您将光标移离窗口,就会显示弹出窗口,这表明弹出窗口工作正常。但我也期待一种背景模糊,所以当我打开弹出窗口时,我希望我的背景保持暗淡或模糊。我已经尝试了几次但失败了。我已经粘贴了下面的代码。任何人都可以加入并帮助我吗?提前致谢!!
<!DOCTYPE html>
<html>
<head>
<!-- jQuery cdn link -->
<script src=
https://code.jquery.com/jquery-3.5.1.min.js>
</script>
<style type="text/css">
.content {
position: fixed;
top: 50%;
left: 50%;
background-image: url('');
transform: translate(-50%, -50%);
width: 500px;
height: auto;
text-align: center;
box-sizing: border-box;
padding: 15px;
z-index: 100;
display: none;
color: #fff;
text-align: center;
/to hide popup initially/
}
.close-btn {
position: absolute;
right: 20px;
top: 15px;
color: white;
border-radius: 50%;
padding: 4px;
cursor: pointer;
}
.text-wrapper{
margin:20px 60px;
}
.popup-text{
font-size: 18px;
}
.popup-text-small{
font-size: 12px;
}
.popup-text-large{
font-size: 48px;
font-weight: bolder;
}
p{
margin: 5px;
}
.box{
border: 1px solid white;
margin: 20px 50px;
}
.links{
display: flex;
justify-content: space-evenly;
margin: 10px 50px;
}
.links a {
border: 1px solid white;
padding: 0 22px;
border-radius: 20px;
color: red;
background-color: #fff;
}
</style>
</head>
<body>
<!-- div containing the popup -->
<div class="content">
<div class="close-btn">
×
</div>
<div class="text-wrapper">
<p class="popup-text">Here you are!</p>
<p class="popup-text-large">$ 12</p>
<p class="popup-text">for your limited edition</p>
<p> with CocaCola</p>
<div class="links">
<a href="" target="_self">Click Here to Subscribe</a>
<a href="" target="_self">Click here to Login</a>
</div>
</div>
</div>
<script type="text/javascript">
// Function to show and hide the popup
function togglePopup() {
jQuery(".content").toggle();
}
jQuery(window).on("mouseleave",function(){
if(jQuery('.content [class="text-wrapper"] .popup-text:visible').length==0 && typeof _satellite.cookie.get('popupshown')=='undefined'){
_satellite.cookie.set('popupshown',true);
togglePopup();
}
})
jQuery(document).on('click', '[class="close-btn"]', function(event) {
togglePopup();
})
</script>
</body>
</html>
【问题讨论】:
-
在这里查看我的答案:stackoverflow.com/questions/69754407/…
标签: javascript html css