bee business
make some clicks
by gion_13
CSS
.bee{
width : 30px;
height : 30px;
background-color : transparent;
position : absolute;
top : -200px;
left : -200px;
background-image:url('http://www.freeimagehosting.net/newuploads/15d9b.gif');
/*
background-image : url('http://l-userpic.livejournal.com/109362111/36557650');
/**/
background-size : 100% 100%;
}
JavaScript
var cursorPos = {};
var minRadius = 30;
var maxRadius = 80;
var beeLimit = 10;
function getMinRadius() {
return minRadius + (Math.random() > 0.5 ? 1 : -1) * Math.random() * 20;
}
function getMaxRadius() {
return maxRadius + (Math.random() > 0.5 ? 1 : -1) * Math.random() * 20;
}
var beeClone = $('<div class="bee" />');
var offset = 300;
$(document).ready(function() {
var img = new Image();
img.src = "http://www.freeimagehosting.net/newuploads/15d9b.gif";
$(this).click(function() {
$('.bee').each(function() {
elipse($(this));
});
$('.bee').length < beeLimit && elipse(beeClone.clone().css({
top: Math.random() > 0.5 ? -offset : $('body').height() + offset,
left: Math.random() > 0.5 ? -offset : $('body').width() + offset
}).appendTo('body'));
});
$(this).mousemove(function(e) {
cursorPos.x = e.clientX;
cursorPos.y = e.clientY;
});
});
function getDistance(bee) {
var p = bee.position();
return {
top: Math.abs(p.top - cursorPos.y),
left: Math.abs(p.left - cursorPos.x)
};
}
function getNewPosition(bee) {
var d = getDistance(bee);
var p = bee.position();
var sign = {
left: p.left > cursorPos.x ? -1 : 1,
top: p.top > cursorPos.y ? -1 : 1
};
return {
left: Math.max(cursorPos.x + getMinRadius() * sign.left, Math.min(cursorPos.x + getMaxRadius() * sign.left, p.left + d.left * 2 * sign.left)),
top: Math.max(cursorPos.y + getMinRadius() * sign.top, Math.min(cursorPos.y + getMaxRadius() * sign.top, p.top + d.top * 2 * sign.top))
};
}
function elipse(bee, callback) {
var bool = Math.random() < 0.5;
var p = getNewPosition(bee);
var speed = 200000 / Math.sqrt(p.top * p.top + p.left * p.left) + Math.random() * 100;
bee.stop().animate({
left: p.left + Math.random() * 10,
top: p.top + Math.random() * 10,
flip: bool
}, speed, 'ellipse',...