javascript - 延迟淡入和淡出页面 - jquery
问题描述
单击功能后,我无法使用 jquery 重新加载我的页面。分配是在body标签中使用带有a标签的点击功能。a 标签必须淡出并重新加载同一页面。所以需要以下几点:
• 将要加载的页面作为参数提供给 onclick 函数。
• 淡出本身需要 1.5 秒。
• 淡出后,您可以使用以下命令加载存储在变量 url 中的页面:
window.location.href = url;
编写 jQuery 代码以在加载网页后隐藏页面。然后确保页面在 1.5 秒内到达。
所以我尝试了这些东西......
Function's like: $("a").click(function(){
$("p").fadeToggle();
$("p").fadeToggle("slow");
$("p").fadeToggle(1500);
我也尝试在代码中使用fadeIn和fadeOut,但它没有帮助..
<html>
<head>
<script src="jquery-3.4.1.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jquery</title>
<script>$(document).ready(function(){
$('a').click(function(e) {
e.preventDefault();
newLocation = this.href;
$('p').fadeOut('slow', newpage);
});
function newpage() {
window.location.href = url;
}
});
</script>
</head>
<body>
<p>Click <a href="#">here</a> to reload the page</p>
</body>
</html>
解决方案
您可以参考下面的片段
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>$(document).ready(function () {
$('a').click(function (e) {
e.preventDefault();
newLocation = this.href;
$('p').fadeOut('slow', newpage);
});
function newpage() {
window.location.href = "http://www.google.com";
}
});
</script>
<p>Click <a href="#">here</a> to reload the page</p>
推荐阅读
- java - Logback 不适用于 Spring Boot 和 Tomcat
- reactjs - 安装 React-native 日历会中断安装
- python - 按组删除 NaN 值
- javascript - CHART.JS 如何将 y 轴上的标签偏移/移动/调整到网格线的中间,而不是在网格线上居中?
- c# - 为什么在运行时肯定会失败的 List.Sort 编译?
- html - 如何调整 CSS 以使关闭按钮看起来在正确的位置?
- c# - 如何从存储为 C# 中的对象的对象 [] 进行转换
- javascript - ReactJS/Javascript:componentDidMount() 和渲染
- linux - 如何根据修改时间对Cent OS 7目录中具有特定扩展名的所有文件进行排序?
- javascript - 异步更新 Zabuto 日历