我有一个带有href链接的标准导航,当用户单击这些链接时,我希望它在1秒钟后触发,因为我想在将它们定向到新页面之前先做一个动画。
我可以延迟然后将用户触发到页面,但这只是方向上的硬编码,但是会有很多链接。
<ul>
<li><a href="/health-and-care/" class="introduction">Introduction</a></li>
<li><a href="/health-and-care/agenda" class="agenda">Speakers, Agenda & Venue</a></li>
<li><a href="/health-and-care/about" class="about">About InterSystems</a></li>
<li class="nolive"><a href="#" class="register-nav"><i class="fas fa-clipboard-check"></i> Register</a></li>
</ul>
jQuery
$('a').click (function (e) {
e.preventDefault();
setTimeout(function () {
window.location.href = "blog.html";
}, 2000);
});
答案 0 :(得分:1)
您可以像这样重定向到位置dynamically
:
$('a').click (function (e) {
e.preventDefault();
let url = $(this).attr('href');
setTimeout(function () {
window.location.href = url;
}, 2000);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li><a href="/health-and-care/" class="introduction">Introduction</a></li>
<li><a href="/health-and-care/agenda" class="agenda">Speakers, Agenda & Venue</a></li>
<li><a href="/health-and-care/about" class="about">About InterSystems</a></li>
<li class="nolive"><a href="#" class="register-nav"><i class="fas fa-clipboard-check"></i> Register</a></li>
</ul>