gpt4 book ai didi

javascript - 显示 :target popup on page load With PURE CSS

转载 作者:行者123 更新时间:2023-11-29 17:46:43 25 4
gpt4 key购买 nike

我知道这是基本问题。但我无法通过它。我只有纯 CSS 中的弹出窗口代码,它会在单击链接标记时弹出。我希望使用 jquery 或 Pure JS 在页面加载时加载此弹出窗口。

请注意,在 CSS 中,我已将“.overlay”类的可见性值设置为无,并在单击时更改为可见。我试图触发点击页面加载并更改页面加载的可见性。不幸的是,两者都失败了。我已经添加了代码片段。帮助我的 friend 。

$(document).ready(function() {
$("#popup1").trigger('click');
});
.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;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="box">
<a id="btn" class="button" href="#popup1">Let me Pop up</a>
</div>

<div id="popup1" class="overlay">
<div class="popup">
<h2>Notification</h2>
<a class="close" href="#">&times;</a>
<div class="content">
App is under-construction.
But payment on referral income has started.
Please stay tuned.
</div>
</div>
</div>

最佳答案

如果你确实想使用 Javascript,你可以通过手动设置哈希来实现:

$(document).ready(function() {
window.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;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="popup1" class="overlay">
<div class="popup">
<h2>Notification</h2>
<a class="close" href="#">&times;</a>
<div class="content">
App is under-construction.
But payment on referral income has started.
Please stay tuned.
</div>
</div>
</div>

关于javascript - 显示 :target popup on page load With PURE CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48719717/

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