我的网站上有一个闪屏,其中有一个 ID 为“splash”的 div,我试图让 div 淡入,然后如果用户单击该 div,它就会淡出并重定向到主站点。如果用户没有点击,它就会淡出并在 10 秒后重定向。
定时重定向有效,但点击功能无效。
<script type="text/javascript">
$(document).ready(function() {
$('#splash').hide();
$('#splash').fadeIn(1000, function() {
$(this).delay(10000).fadeOut(1000, function() {
window.location = 'http://www.examle.com'; });
$(this).click().fadeOut(1000,function() {
window.location = 'http://www.example.com'; });
});
});
</script>
任何帮助都会很棒
尝试这个:
$(document).ready(function() {
$('#splash').hide();
$('#splash').click(function(){
$(this).fadeOut(1000,function() {
window.location = 'http://www.example.com'; });
});
$('#splash').fadeIn(1000, function() {
window.setTimeout ( function() {
$('#splash').fadeOut(1000, function() {
window.location = 'http://www.example.com'; }) }
, 10000);
});
});
我对示例所做的更改:
我已经将点击处理程序的设置移到了 fadeOut 函数之外(更好的做法,恕我直言),并且我已经将对delay() 的调用更改为setTimeout()。
不同之处在于,delay() 不允许在后台执行其他 jQuery 代码,而 setTimeout() 则允许。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)