jquery重定向点击或10秒后 [英] jquery redirect on click or after 10 seconds

查看:120
本文介绍了jquery重定向点击或10秒后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个网站上有一个spash屏幕有一个div与IDsplash我试图使div褪色,然后如果用户点击div它淡出和重定向到主要网站。如果用户不点击它只是淡出和10秒后重定向。

I have a spash screen on a website that has a div with the ID of "splash" i'm trying to make the div fade in then if the user clicks on the div it fades out and redircts to the main site. If the user dosen't click it just fades out and redirects after 10 seconds.

定时重定向正常工作,但不是点击功能。

The timed redirect is working but not the click function.

    <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函数之外(更好的做法,IMHO) '

I've moved setting the click handler outside the fadeOut function (better practice, IMHO) and I've changed your call to delay() to a setTimeout().

不同的是,delay()不允许在后台执行其他jQuery代码,而setTimeout()会。

The difference is, delay() will not allow other jQuery code to be executed in the background, while setTimeout() will.

这篇关于jquery重定向点击或10秒后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆