I want to use this code on my website.
I tried but failed. Can anyone write complete html code (starting from html tag till closure of html tag.)
This is the working script. http://ift.tt/1K9cklk
I have try it on http://ift.tt/1W7DFO0.
Please help me out.
Thanks
function randomFromTo(from, to){
return Math.floor(Math.random() * (to - from + 1) + from);
}
function moveRandom(obj) {
/* get container position and size
* -- access method : cPos.top and cPos.left */
var cPos = $('#container').offset();
var cHeight = $('#container').height();
var cWidth = $('#container').width();
// get box padding (assume all padding have same value)
var pad = parseInt($('#container').css('padding-top').replace('px', ''));
// get movable box size
var bHeight = obj.height();
var bWidth = obj.width();
// set maximum position
maxY = cPos.top + cHeight - bHeight - pad;
maxX = cPos.left + cWidth - bWidth - pad;
// set minimum position
minY = cPos.top + pad;
minX = cPos.left + pad;
// set new position
newY = randomFromTo(minY, maxY);
newX = randomFromTo(minX, maxX);
obj.animate({
top: newY,
left: newX
}, 10000, function() {
moveRandom(obj);
});
}
$('.latestblock').each(function() {
moveRandom($(this));
});
Aucun commentaire:
Enregistrer un commentaire