-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (22 loc) · 802 Bytes
/
index.js
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
import popcornImg from './popcorn.png'
const $ = window.$ = require('jquery')
function rand (min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
let popcorn = []
$('#pushForPopcorn').click(() => {
const newElement = $('<img src="./' + popcornImg + '" height="100"/>')
$('body').append(newElement)
newElement.css('left', rand(1, 100) + '%').css('transform', 'rotate(' + rand(0, 359) + 'deg)')
popcorn.unshift(newElement)
const windowHeight = $(window).height()
const lineHeight = newElement.height()
const newPosition = windowHeight - lineHeight
newElement.animate({top: newPosition, duration: rand(250, 2500)}, 1000, function () {
newElement.css({
bottom: 0,
top: 'auto'
})
})
popcorn.splice(200).forEach(e => e.fadeOut('slow'))
})