is it possible to insert a jquery function in a javascript class? For example I have the following JS class:
function FloatingImage() {
var delay, duration;
var moveRight = function($image)
{
$image.delay(delay).animate(
{
left: $image.parent().width() - $image.width()
},
{
duration: duration,
complete: function(){ moveLeft($image) }
});
},
moveLeft = function($image){
$image.delay(delay).animate({
left: 0
}, {
duration: duration,
complete: function(){ moveRight($image) }
});
};
this.constructor = function (delay, duration) {
this.delay = delay;
this.duration = duration;
};
}
The following support function:
function rand(l,u) // lower bound and upper bound
{
return Math.floor((Math.random() * (u-l+1))+l);
}
And then calling it, assuming there are 2 divs #imgleft and #imgright with both 2 images as background, with:
$(function(){
var $imageL = $('#imgleft'),
$imageR = $('#imgright');
var fi1 = new FloatingImage();
fi1.constructor(rand(400,600), rand(1500,3000));
var fi2 = new FloatingImage();
fi2.constructor(rand(400,600), rand(1500,3000));
fi1.moveRight($imageL);
fi2.moveLeft($imageR);
});