Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Browser crashes help!!

    Hi, i wanted to know whats wrong with this coding as its making the browser crash, firefox 5

    $(document).ready(function() {

    /* open rel=external in new window */
    $('a[rel=external]').attr('target', '_blank');

    /*Scrolling background clouds */

    var offset = 600;
    var offseta = 1450;

    function scrollbackground() {
    // decrease the offset by 1, or if its less than 1 increase it by
    // the background height minus 1
    offset = offset + 1;
    offseta = offseta + 1;
    // apply the background position
    if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)))
    {
    $('#cloud2').css("background-position", offseta + "px top");
    }
    else {
    $('#cloud').css("background-position", offset + "px top");
    $('#cloud2').css("background-position", offseta + "px top");
    }
    // call self to continue animation
    setTimeout(function() {
    scrollbackground();
    }, 100
    );
    }

    // Start the animation
    scrollbackground();

    }); //end


  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    First of all: Please use [ code ] or the # octathorpe symbol for your code. It will allow you proper indentation.

    Second: Your code will increase offset and offseta indefinitely. You have no termination condition for your loop.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,635 Times in 4,597 Posts
    And thirdly, the code doesn't match the comment.

    Comment:
    // decrease the offset by 1
    Code:
    Code:
    offset = offset + 1;
    offseta = offseta + 1;
    Where is there any "decrease"??
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •