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.
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).
$('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),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With