sal*_*lem 2 html javascript jquery
我正在寻找一种方法让页面上的每个链接延迟一秒,以便可以发生淡出动画本质上,您单击图像上的区域并且图像淡出,但如果没有延迟,没看到动画.我在这张图片上有4个区域.两个转到第A页,两个转到第b页.有什么想法吗?
您可以捕获(并暂停)链接单击事件并设置超时以在1000ms后重定向到链接的href属性.
使用jQuery:
$("#a_context a").click(function(e) {
e.preventDefault();
var destination = $(this).attr('href');
setTimeout(function() { window.location.href = destination; }, 1000);
});Run Code Online (Sandbox Code Playgroud)
不确定这是不是最好的方式,但我能想到的只是.
你可以用jQuery做到这一点:
$('a').click(function(e) {
var anchor = $(this), h;
h = anchor.attr('href');
e.preventDefault();
anchor.animate({'opacity' : 0}, 1000, function() {
window.location = h;
});
});
Run Code Online (Sandbox Code Playgroud)