-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
97 lines (69 loc) · 2.13 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<style type="text/css">
div.a {
background-image: url('unicorn.png');
position:fixed;
top: 50%;
left: 50%;
cursor: pointer;
width: 70px;
height: 70px;
background-size: contain;
}
</style>
<div class='a'></div>
<div class='a'></div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
animateDiv();
$('body').on('click','.a',function () {
$('body').append('<div class="a"></div><div class="a"></div>');
animateDiv();
})
});
function makeNewPosition(){
// Get viewport dimensions (remove the dimension of the div)
var h = $(window).height()/1.5;
var w = $(window).width()/1.5;
var nh = Math.floor(Math.random() * h);
var nw = Math.floor(Math.random() * w);
return [nh,nw];
}
function animateDiv(elem){
elem = elem || $('.a');
elem.each(function () {
$(this).yolo();
});
};
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
jQuery.fn.yolo = function() {
var degrees = getRandomInt(0,360);
var newq = makeNewPosition();
var anim = getRandomInt(1400,5600);
var width = getRandomInt(70,300);
var height = 548*width/510;
$(this).css({'-webkit-transform' : 'rotate('+ degrees +'deg)',
'-moz-transform' : 'rotate('+ degrees +'deg)',
'-ms-transform' : 'rotate('+ degrees +'deg)',
'transform' : 'rotate('+ degrees +'deg)',
'width' : width + 'px',
'height' : height + 'px',
'transition' : 'transform '+ anim +'ms ease,' + 'width '+ anim +'ms ease,' + 'height '+ anim +'ms ease',
});
$(this).animate({ top: newq[0], left: newq[1] },anim, function(){
animateDiv($(this));
});
return $(this);
};
</script>
</html>