gpt4 book ai didi

javascript - 使用javascript激活css弹出窗口

转载 作者:行者123 更新时间:2023-11-28 15:31:53 25 4
gpt4 key购买 nike

您好,我有这个 CSS 弹出窗口,当前设置了一个按钮。我也有这个 JavaScript“鼠标点击计数器”。我想要发生的是当计数器归零时弹出窗口出现。我认为这很容易,我只是没有足够的 JavaScript 经验。谢谢

CSS 弹出式

.overlay:target {
visibility: visible;
opacity: 1;
}

.popup {
margin: 70px auto;
padding: 20px;
background: #fff;
border-radius: 5px;
width: 30%;
position: relative;
transition: all 5s ease-in-out;
}

.popup h2 {
margin-top: 0;
color: #333;
font-family: Tahoma, Arial, sans-serif;
}
.popup .close {
position: absolute;
top: 20px;
right: 30px;
transition: all 200ms;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #333;
}
.popup .close:hover {
color: #06D85F;
}
.popup .content {
max-height: 30%;
overflow: auto;
}

@media screen and (max-width: 700px){
.box{
width: 70%;
}
.popup{
width: 70%;
}
}

JavaScript 鼠标点击计数器(从 10 开始,然后从那里开始)

var number = 10;

document.onclick = function(){
number --;
document.getElementById("clicks").innerHTML = number;
}

我倾向于不澄清事情,所以只是为了确定。一旦计数器降为零,我想弹出窗口以激活所有功能。包括屏幕不透明度。谢谢!

jsfiddle - 鼠标点击计数器 here

jsfiddle - 弹出 here

最佳答案

这是检查 number 值的方法,如果 number > -1 则递增 #clicks,如果 number == 0,更新哈希值以便显示弹出窗口。

var number = 10;

document.onclick = function() {
number--;
if (number > -1) {
document.getElementById("clicks").innerHTML = number;
(number == 0) && (location.hash = '#popup1')
}
};
.overlay {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
transition: opacity 500ms;
visibility: hidden;
opacity: 0;
}
.overlay:target {
visibility: visible;
opacity: 1;
}

.popup {
margin: 70px auto;
padding: 20px;
background: #fff;
border-radius: 5px;
width: 30%;
position: relative;
transition: all 5s ease-in-out;
}


.popup h2 {
margin-top: 0;
color: #333;
font-family: Tahoma, Arial, sans-serif;
}
.popup .close {
position: absolute;
top: 20px;
right: 30px;
transition: all 200ms;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #333;
}
.popup .close:hover {
color: #06D85F;
}
.popup .content {
max-height: 30%;
overflow: auto;
}

@media screen and (max-width: 700px){
.box{
width: 70%;
}
.popup{
width: 70%;
}
}
<div id="clicks"></div>
<div id="popup1" class="overlay">
<div class="popup">
<h2>WOW!</h2>
<a class="close" href="#">&times;</a>
<div class="content">
<center>Lets see how you did!!</center>
</div>
</div>
</div>

关于javascript - 使用javascript激活css弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44555856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com