当我有一个与jQuery或JavaScript事件连接的链接,例如:
<a href="#">My Link</a>
Run Code Online (Sandbox Code Playgroud)
如何防止页面滚动到顶部?当我从锚点中删除href属性时,页面不会滚动到顶部,但链接似乎不是可点击的.
所以,我正在使用一些 css3 弹出窗口/模式。我对它们的工作方式非常满意,但是在模式关闭后,页面滚动回到顶部,我不确定为什么会发生这种情况。
你可以在这里看到行为这是 html 的片段
<div class="flip">
<div class="front">
<img src="images/SDG_ICONS/SDG01.png" alt="No Poverty" />
</div>
<div class="back">
<ul>
<a href="#ared-no-poverty"><li>ARED</li></a>
<a href="#agrocenta-no-poverty"><li>AgroCenta</li></a>
<a href="#tilly-no-poverty"><li>Tilly's Farm</li></a>
</ul>
</div>
</div>
<div id="ared-no-poverty" class="overlay">
<div class="popup">
<h2>ARED</h2>
<a class="close" href="#"> ×</a>
<p class="popup">Some text in here</p>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我用于弹出窗口/模式的 css
.popup {
margin: 70px auto;
padding: 20px;
background: #fff;
border-radius: 5px;
width: 30%;
position: relative;
transition: all 5s ease-in-out;
z-index: 2;
}
.popup h2 {
margin-top: 0;
color: #333;
font-family: Tahoma, Arial, …Run Code Online (Sandbox Code Playgroud)