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

  • Home
  • SEARCH
  • 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 7614999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:32:46+00:00 2026-05-31T02:32:46+00:00

I have the following snippet of code that loops through the jQuery animate function

  • 0

I have the following snippet of code that loops through the jQuery animate function endlessly. It works fine on Chrome, but fails after the first animate call on IE. My questions are:

  • How can I make this work in IE (9)?
  • How can I add a delay after the first loop? I want there to be a delay between consecutive pulses.

    #container {
    position : relative;
    width    : 500px;
    height   : 200px;
    overflow : hidden;
    opacity: 1;
    }
    

.

 #container > img {
    position : absolute;
    top      : 0;
    left     : 0;
    }

.

$(window).load(function(){
$(function () {
    var $image = $('#container').children('img');
    function animate_img() {
        if ($image.css('opacity') == '1') {
            $image.animate({opacity: '0.4'}, 2000, function () {
                animate_img();
            });
        } else {console.log('2');
            $image.animate({opacity: '1'}, 2000, function () {
                animate_img();
            });
        }
    }
    animate_img();
});

});

.

<div id="container">
  <img src="blah.jpg" width="500" height="375" />
</div>
  • 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-31T02:32:48+00:00Added an answer on May 31, 2026 at 2:32 am

    Remove the console.log() statement from the else branch and it should work in IE – IE doesn’t like console.log() unless the console is actually open, whereas (most) other browsers either ignore it or log in a way you can see if you open the console later. (I don’t have IE9, but that’s all it took to fix it when I tested it in IE8.)

    Also it doesn’t make sense to have a document ready handler inside a $(window).load() handler, so you should remove one or the other.

    As far as adding a delay between consecutive pulses, just use jQuery’s .delay() function before calling .animate() in the else branch, like this:

    $(function () {
        var $image = $('#container').children('img');
        function animate_img() {
            if ($image.css('opacity') == '1') {
                $image.animate({opacity: '0.4'}, 2000, function () {
                    animate_img();
                });
            } else { // console.log removed from this spot
                $image.delay(500).animate({opacity: '1'}, 2000, function () {
                    animate_img();
                });
            }
        }
        animate_img();
    });
    

    P.S. Given that the anonymous functions you’ve got for the .animate() complete callbacks don’t do anything except call animate_img() you can remove the anonymous functions and just pass animate_img directly. So you can make the function much shorter if you wish:

    $(function () {
      var $image = $('#container').children('img');
      function animate_img() {
        var fade = $image.css('opacity') == '1';
        $image.delay(fade?1:500).animate({opacity:fade?'0.4':'1'},2000,animate_img);
      }
      animate_img();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code snippet from my PowerShell script that... Loops through a
I have the following snippet of code that's generating the Use new keyword if
I have following code snippet that i use to compile class at the run
I have the following snippet of code (I'm using jQuery 1.4.2): $.post('/Ads/GetAdStatsRow/', { 'ad_id':
I have the following code snippet that shows a list of numbers, and highlights
I have the following snippet of code (as an example) that looks up a
I have the following code snippet: $.getJSON(http://localhost:8080/images, function(data) { var items = []; $.each(data,
I have code that looks like the following: //unrelated code snipped resolver.reset(new tcp::resolver(iosvc)); tcp::resolver::query
If we have the following 2 snippets of code in c++ that do the
I have a line of PHP code that does the following: $xml = <xml><request>...[snipped

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.