bubbleworks
Advanced tools
Comparing version 1.1.1 to 1.2.1
50
index.js
@@ -10,3 +10,3 @@ | ||
var render = function render(particles, ctx, width, height) { | ||
requestAnimationFrame(function() { | ||
requestAnimationFrame(function () { | ||
if (!isRendered) { | ||
@@ -18,3 +18,3 @@ return | ||
ctx.clearRect(0, 0, width, height) | ||
particles.forEach(function(p, i) { | ||
particles.forEach(function (p, i) { | ||
p.x += p.speed * Math.cos(p.rotation * Math.PI / 180) | ||
@@ -27,3 +27,7 @@ p.y += p.speed * Math.sin(p.rotation * Math.PI / 180) | ||
p.y += p.yVel | ||
if (p.opacity < 0 || p.radius < 0) return | ||
if (p.opacity < 0 || p.radius < 0) { | ||
return | ||
} | ||
ctx.beginPath() | ||
@@ -38,17 +42,27 @@ ctx.globalAlpha = p.opacity | ||
function explode (x, y, colors) { | ||
function explode (opts) { | ||
if (!opts) { | ||
throw new Error('Missing options for bubbleworks') | ||
} | ||
var x = opts.x | ||
var y = opts.y | ||
var colors = opts.colors | ||
var parentNode = opts.parentNode || document.body | ||
var particles = [] | ||
var ratio = window.devicePixelRatio | ||
var c = document.createElement("canvas") | ||
var ctx = c.getContext("2d") | ||
c.style.position = "absolute" | ||
c.style.left = x - 100 + "px" | ||
c.style.top = y - 100 + "px" | ||
c.style.pointerEvents = "none" | ||
c.style.width = 200 + "px" | ||
c.style.height = 200 + "px" | ||
var c = document.createElement('canvas') | ||
var ctx = c.getContext('2d') | ||
c.style.position = 'absolute' | ||
c.style.left = x - 100 + 'px' | ||
c.style.top = y - 100 + 'px' | ||
c.style.pointerEvents = 'none' | ||
c.style.width = 200 + 'px' | ||
c.style.height = 200 + 'px' | ||
c.style.zIndex = 100 | ||
c.width = 200 * ratio | ||
c.height = 200 * ratio | ||
document.body.appendChild(c) | ||
parentNode.appendChild(c) | ||
@@ -72,7 +86,13 @@ for (var i = 0; i < bubbles; i++) { | ||
setTimeout(function() { | ||
document.body.removeChild(c) | ||
isRendered = true | ||
setTimeout(function () { | ||
parentNode.removeChild(c) | ||
}, 1000) | ||
setTimeout(function () { | ||
isRendered = false | ||
}, 1100) | ||
} | ||
module.exports = explode |
{ | ||
"name": "bubbleworks", | ||
"version": "1.1.1", | ||
"version": "1.2.1", | ||
"main": "index.js", | ||
"license": "MIT" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2261
78