Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7521519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:15:00+00:00 2026-05-30T02:15:00+00:00

I am struggling with my first jQuery script. I’ve got a DIV on my

  • 0

I am struggling with my first jQuery script. I’ve got a DIV on my page that is set to hide via CSS. Then, I have this script that runs to make it fade in, fade out, then fade in again:

<script type="text/javascript">
  (function($) {
    $(function() {
      $('#abovelogo').fadeIn(1000).delay(2000).fadeOut(1500).delay(2000).fadeIn(1500);
    }); 
  })(jQuery);
</script>

This part works fine. Now, my question:

How do I change it so that this script runs loops (forever) instead of just once?

Thanks in advance!
-Nate

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:15:02+00:00Added an answer on May 30, 2026 at 2:15 am

    Put your code inside a setInterval:

    $(function () {
        setInterval(function () {
            $('#abovelogo').fadeIn(1000).delay(2000).fadeOut(1500).delay(2000).fadeIn(1500);
        }, 5000);
    });
    

    Since you will be running this as long as the page is active then you should do everything you can to optimize your code, for instance you can cache the selection outside of the interval:

    $(function () {
        var $element = $('#abovelogo');
        setInterval(function () {
            $element.fadeIn(1000).delay(2000).fadeOut(1500).delay(2000).fadeIn(1500);
        }, 5000);
    });
    

    Docs for setInterval: https://developer.mozilla.org/en/window.setInterval

    Also, instead of using .delay() you can use the callback functions in each animation to call one animation after another:

    $(function () {
        var $element = $('#abovelogo');
        setInterval(function () {
            $element.fadeIn(1000, function () {
                $element.fadeOut(1500, function () {
                    $element.fadeIn(1500)
                });
            });
        }, 5000);
    });
    

    Here is a demo: http://jsfiddle.net/xsATz/

    You can also use setTimeout and call a function recursively:

    $(function () {
        var $element = $('#abovelogo');
        function fadeInOut () {
            $element.fadeIn(1000, function () {
                $element.fadeOut(1500, function () {
                    $element.fadeIn(1500, function () {
                        setTimeout(fadeInOut, 500);
                    });
                });
            });
        }
    
        fadeInOut();
    });
    

    Here is a demo: http://jsfiddle.net/xsATz/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been writing my first jQuery plugin and struggling to find a means
I have two jQuery UI Autocomplete widgets set up. With the first autocomplete, the
I have a JQuery Accordion as below; <div id=accordion> <h3 class=ui-accordion-header><a id=link1 href=#>First Header</a></h3>
I have been struggling with a problem that at first glance might look easy
I'm using NHibernate for the first time and struggling. On web page one, I
I'm struggling to find the right terminology here, but if you have jQuery object...
First, I know that there are jQuery plugins for search suggest. The reason I'm
I have a list that has 5 items in, the first one (on load)
I'm struggling with a custom jQuery validator, its my first go at one and
Using JQuery, I am loading a div from an external HTML page into fancybox

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.