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 9098093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:16:47+00:00 2026-06-17T00:16:47+00:00

I’m working on a web art project that requires many objects to fade in

  • 0

I’m working on a web art project that requires many objects to fade in and fade out at certain intervals (I was hoping to use 100 or more objects). I’ve got jQ reading an XML file containing the metadata and appending Ps to the body, which are then told to fade in and fade out based on info in the metadata. I’m using setTimeouts to accomplish this.

The piece is ending up to be very resource intensive. Within a minute or two of loading the page up, my machine starts wheezing. (Alternatively, I’m thinking that it might not be a resource issue but a graphical one.)

Does anyone have some advice for making this more resource-friendly/efficient? I appreciate any help!

Here’s the live link: http://justwhatdoyoucallthis.com/trynottogiveup/ (Beware of resource hog)

Here’s the relevant script:

$.ajax({
    type: 'get',
    url: 'problems.xml', /* ...which contains like 99 problems */
    dataType: 'xml',
    success: function(problems) {
        $(document).ready(function() {
            var winWidth=$(window).width();
            var winHeight=$(window).height();
            $(problems).find('problem').each(function() {
                var probType=$(this).attr('type');
                var probAppear=$(this).attr('appear');
                var probName=$(this).children('name').text();
                var probID=(probName.replace(/\s/g, '')).toLowerCase();
                var probIntensity=($(this).children('intensity').text()+5)*10;
                var probInterval=$(this).children('interval').text();
                var probDuration=$(this).children('duration').text();
                var ranLeft=Math.random()*winWidth-(probIntensity/2);
                var ranTop=Math.random()*winHeight-(probIntensity/2);
                $('body').append('<p id="'+probID+'" class="'+probType+'" style="left: '+ranLeft+'px; top: '+ranTop+'px; height: '+probIntensity+'px; width: '+probIntensity+'px;"><span>'+probName+'</span></p>');
                (function showLoop() {
                    if(probAppear=='fade') { var fadeInDuration=1000; } else { var fadeInDuration=0; }
                    $('#'+probID).delay(probInterval*1000).fadeIn(fadeInDuration).delay(probDuration*1000).fadeOut(1000);
                    setTimeout(showLoop, 1000);
                })();
            });
        });
    }
});
  • 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-06-17T00:16:48+00:00Added an answer on June 17, 2026 at 12:16 am

    Here’s an optimized version of your code, but like bvukelic said the whole concept would probably be more efficient with canvas.

    The problem I see with the code anyway is that delay and fade actions are indeed called synchronously, but the timeout is executed asynchronously, meaning that after a while you have multiple streams of actions on the same object (and this up to a hundred times).

    So the solution would be to append the repeated timeout as callback to the .fadeOut() action.

    $(function() {
        var $win = $(window),
            winWidth = $win.width(),
            winHeight = $win.height(),
            showLoop = function(prob) {
                var fadeInDuration = prob.appear == 'fade' ? 1000 : 0;
                $('#'+prob.id)
                    .delay(prob.interval*1000)
                    .fadeIn(fadeInDuration)
                    .delay(prob.duration*1000)
                    .fadeOut(1000, function() {
                        window.setTimeout(function() {
                            showLoop(prob); // synchronously repeated callback
                        }, 1000);
                    });
            };
    
        $.ajax({
            type: 'get',
            url: 'problems.xml', /* ...which contains like 99 problems */
            dataType: 'xml',
            success: function(problems) {        
                $('problem', problems).each(function() {
                    var $t = $(this),
                        probName = $('name', this).text(),
                        prob = {
                            type: $t.attr('type'),
                            appear: $t.attr('appear'),
                            name: probName,
                            id: probName.replace(/\s/g, '').toLowerCase(),
                            intensity: (parseInt($('intensity', this).text()) + 5) * 10,
                            interval: parseInt($('interval', this).text()),
                            duration: parseInt($('duration', this).text()),
                            pos: {
                                top = Math.random()*winHeight-(prob.intensity/2),
                                left = Math.random()*winWidth-(prob.intensity/2)
                            }
                        };
    
                    $('<p>')
                        .append('<span>'+prob.name+'</span>')
                        .attr('id', prob.id)
                        .addClass(prob.type)
                        .width(prob.intensity)
                        .height(prob.intensity)
                        .css({
                            top: prob.pos.top,
                            left: prob.pos.left,
                        })
                        .appendTo('body');
    
                    showLoop(prob);
                });
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am confused How to use looping for Json response Array in another Array.
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace

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.