Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with this code

function moveit() {

    var newTop = Math.floor(Math.random()*350);
    var newLeft = Math.floor(Math.random()*1024);
    var newDuration = 9000

    $('#friends').animate({
      top: newTop,
      left: newLeft,
 !!! -->     width: "+="+((newTop-$('friends').css('top'))*3),
      }, newDuration, function() {
        moveit();
      });

}

$(document).ready(function() {
    moveit();
});

It is supposed to make an image fly around (works). I added the line marked with the "!!! -->" that should make the image get bigger the closer it is to the bottom of the page.

What did I do wrong? The code doesn't throw any errors.

like image 931
Freesnöw Avatar asked May 09 '11 17:05

Freesnöw


People also ask

What is this in code?

this, self, and Me are keywords used in some computer programming languages to refer to the object, class, or other entity of which the currently running code is a part. The entity referred to by these keywords thus depends on the execution context (such as which object is having its method called).


1 Answers

$('friends').css('top') returns a string, you'll need to convert this to an int before you can use it to subtract from newTop

parseInt($('friends').css('top'), 10)

Would do the trick

Also you need to use an ID or class identifier in your jQuery selector, either '#friends' or '.friends' but I imagine you're looking for something with the ID of friends

Try this

width: "+="+((newTop - parseInt($('#friends').css('top'), 10))*3),
like image 167
Jimmy Avatar answered Oct 23 '22 13:10

Jimmy