Bro*_*ke. 4 javascript jquery splash-screen click delay
我在一个网站上有一个spash屏幕,其中有一个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>
Run Code Online (Sandbox Code Playgroud)
任何帮助都会很棒
试试这个:
$(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);
});
});?
Run Code Online (Sandbox Code Playgroud)
我对示例所做的更改:
我已经将点击处理程序设置在fadeOut函数之外(更好的做法,恕我直言),并且我已将对delay()的调用更改为setTimeout().
不同的是,delay()不允许在后台执行其他jQuery代码,而setTimeout()则会.
| 归档时间: |
|
| 查看次数: |
25901 次 |
| 最近记录: |