为什么单击事件在 MacOS Safari 上不起作用?
Why is click event not working on MacOS Safari?
我有这个jQuery:
jQuery(document).ready(function($) {
// When the page is loading show the #preloader element
$("#preloader").fadeOut("slow");
$("#page-container").fadeIn("slow");
// When an article with article grid is clicked, display the loader
$("a").on("touchstart click", function() {
$("#preloader").fadeIn("slow");
});
});
它应该如何工作:
页面加载并立即显示#preloader 元素。页面加载后,#preloader 元素淡出,#page-container 元素淡入。
然后,当您单击 link 时,#preloader 元素会在浏览器加载下一页时淡入。回到步骤 1.
因此页面加载之间可以无缝过渡。
这在 Firefox 和 Chrome 上运行良好。但是在 Safari 和所有 iOS 浏览器上,第 2 步中的点击事件不起作用。 #preloader 元素在新页面加载之前不会淡入。
我尝试添加让#preloader 元素淡入的 preventDefault,但浏览器从未重定向到新页面。
有什么想法吗?
解决了这个问题。这是我最终使用的:
jQuery(document).ready(function($) {
// When the page is loading show the #preloader element
$("#preloader").fadeOut("slow");
$("#page-container").fadeIn("slow");
// When an link is clicked, display the loader
$("a").on("touchstart click", function() {
event.preventDefault();
newLocation = this.href;
$("#preloader").fadeIn("slow", newpage);
});
function newpage() {
window.location = newLocation;
}
});
我有这个jQuery:
jQuery(document).ready(function($) {
// When the page is loading show the #preloader element
$("#preloader").fadeOut("slow");
$("#page-container").fadeIn("slow");
// When an article with article grid is clicked, display the loader
$("a").on("touchstart click", function() {
$("#preloader").fadeIn("slow");
});
});
它应该如何工作:
页面加载并立即显示#preloader 元素。页面加载后,#preloader 元素淡出,#page-container 元素淡入。
然后,当您单击 link 时,#preloader 元素会在浏览器加载下一页时淡入。回到步骤 1.
因此页面加载之间可以无缝过渡。
这在 Firefox 和 Chrome 上运行良好。但是在 Safari 和所有 iOS 浏览器上,第 2 步中的点击事件不起作用。 #preloader 元素在新页面加载之前不会淡入。
我尝试添加让#preloader 元素淡入的 preventDefault,但浏览器从未重定向到新页面。
有什么想法吗?
解决了这个问题。这是我最终使用的:
jQuery(document).ready(function($) {
// When the page is loading show the #preloader element
$("#preloader").fadeOut("slow");
$("#page-container").fadeIn("slow");
// When an link is clicked, display the loader
$("a").on("touchstart click", function() {
event.preventDefault();
newLocation = this.href;
$("#preloader").fadeIn("slow", newpage);
});
function newpage() {
window.location = newLocation;
}
});