最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Setting a document ready timeout, how to set it up - Stack Overflow

programmeradmin2浏览0评论

Hopefully it will be a quick and easy question,

I am creating a simple function, but need to trigger it about 3-4 seconds after the page is loaded, just do not know how.

Here is my script

$(function () {
    var slideout = $('#slideout');
    slideout.animate({
        right: '-200px'
    }, 1000, function () {});
    $(".out").toggle(function () {
        $(this).addClass('in');
        slideout.animate({
            right: '0px'
        }, {
            queue: false,
             duration: 500
        });
    }, function () {
        $(this).removeClass('in');
        slideout.animate({
            right: '-200px'
        }, {
            queue: false,
            duration: 500
        });
    });
    $(".close").click(function () {
        $(this).removeClass('out');
        slideout.animate({
            right: '-200px'
        }, {
            queue: false,
            duration: 1000
        });
        slideout.fadeOut({
            duration: 1000
        });
    });
});

Any help is highly appreciated.

Hopefully it will be a quick and easy question,

I am creating a simple function, but need to trigger it about 3-4 seconds after the page is loaded, just do not know how.

Here is my script

$(function () {
    var slideout = $('#slideout');
    slideout.animate({
        right: '-200px'
    }, 1000, function () {});
    $(".out").toggle(function () {
        $(this).addClass('in');
        slideout.animate({
            right: '0px'
        }, {
            queue: false,
             duration: 500
        });
    }, function () {
        $(this).removeClass('in');
        slideout.animate({
            right: '-200px'
        }, {
            queue: false,
            duration: 500
        });
    });
    $(".close").click(function () {
        $(this).removeClass('out');
        slideout.animate({
            right: '-200px'
        }, {
            queue: false,
            duration: 1000
        });
        slideout.fadeOut({
            duration: 1000
        });
    });
});

Any help is highly appreciated.

Share Improve this question asked Oct 20, 2013 at 18:23 AlexBAlexB 2,1746 gold badges28 silver badges66 bronze badges 3
  • 1 Googling javascript timeout should get you on the right track! – Pekka Commented Oct 20, 2013 at 18:26
  • $(function(){ setTimeout(myfunc, 3000); /*other code */}) the passed function is invoked on document ready. you can add your timeout code there. – gp. Commented Oct 20, 2013 at 18:27
  • 2 curious.. why 3-4 seconds? – omma2289 Commented Oct 20, 2013 at 18:28
Add a comment  | 

2 Answers 2

Reset to default 16
$(document).ready(function(){
   setTimeout(function(){

         //YOUR CODE

   },4000);
});
$(function () {
    var doInteresting = function () {
        var slideout = $('#slideout');
        slideout.animate({
            right: '-200px'
        }, 1000, function () {});
        $(".out").toggle(function () {
            $(this).addClass('in');
            slideout.animate({
                right: '0px'
            }, {
                queue: false,
                duration: 500
            });
        }, function () {
            $(this).removeClass('in');
            slideout.animate({
                right: '-200px'
            }, {
                queue: false,
                duration: 500
            });
        });
        $(".close").click(function () {
            $(this).removeClass('out');
            slideout.animate({
                right: '-200px'
            }, {
                queue: false,
                duration: 1000
            });
            slideout.fadeOut({
                duration: 1000
            });
        });
    }

    setTimeout(doInteresting, 3000);
});
发布评论

评论列表(0)

  1. 暂无评论