
Security News
OWASP 2025 Top 10 Adds Software Supply Chain Failures, Ranked Top Community Concern
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.
bubble-hearts
Advanced tools
(<3kb) 💖Bubble hearts animation.(Canvas 实现直播间点赞动画)

$ npm install --save-dev bubble-hearts
let stage = new BubbleHearts();
let canvas = stage.canvas;
let context = stage.context;
canvas.width = 200;
canvas.height = 400;
canvas.style['width'] = '200px';
canvas.style['height'] = '400px';
document.body.appendChild(canvas);
let image = new Image;
image.onload = () => {
stage.bubble(image);
};
image.src = src;
stage.bubble( image : Image/Canvas, duration : Number, handler : Function )
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| image | Image/Canvas | * | - | Let this image bubbles in canvas. |
| duration | Number | - | 3000 | The duration of animation. |
| handler | Function | - | @see handler | The handler of animation. |
handler( lifespan : Number )
| Param | Type | Description |
|---|---|---|
| lifespan | Number | From 1 to 0; 1 means full live; 0 means over. |
/**
* Create a default Render
* @param {Canvas} canvas canvas
* @param {Context} context context
* @return {Function} handler
*/
function createRender ( image, canvas, context ) {
const zoomInStage = random.uniformDiscrete(89, 91) / 100;
const zoomInRest = 1 - zoomInStage;
const basicScale = (random.uniformDiscrete(45, 60) + random.uniformDiscrete(45, 60)) / 100;
let getScale = ( lifespan ) => {
if (lifespan > zoomInStage) {
return Math.max(((1 - lifespan) / zoomInRest).toFixed(2), 0.1) * basicScale;
} else {
return basicScale;
}
};
const basicRotate = random.uniformDiscrete(-30, 30);
let getRotate = ( lifespan ) => {
return basicRotate;
};
const offset = 10;
const basicTranslateX = canvas.width / 2 + random.uniformDiscrete(-offset, offset);
const amplitude = (canvas.width - Math.sqrt(Math.pow(image.width, 2) + Math.pow(image.height, 2))) / 2 - offset;
const wave = random.uniformDiscrete(amplitude * 0.8, amplitude) * (random.uniformDiscrete(0, 1) ? 1 : -1);
const frequency = random.uniformDiscrete(250, 400);
let getTranslateX = ( lifespan ) => {
if (lifespan > zoomInStage) {
return basicTranslateX;
} else {
return basicTranslateX + wave * Math.sin(frequency * (zoomInStage - lifespan) * Math.PI / 180);
}
};
let getTranslateY = ( lifespan ) => {
return image.height / 2 + (canvas.height - image.height / 2) * lifespan;
};
const fadeOutStage = random.uniformDiscrete(14, 18) / 100;
let getAlpha = ( lifespan ) => {
if (lifespan > fadeOutStage) {
return 1;
} else {
return 1 - ((fadeOutStage - lifespan) / fadeOutStage).toFixed(2);
}
};
return ( lifespan ) => {
if (lifespan >= 0) {
let scale = getScale(lifespan);
let rotate = getRotate(lifespan);
let translateX = getTranslateX(lifespan);
let translateY = getTranslateY(lifespan);
context.translate(translateX, translateY);
context.scale(scale, scale);
context.rotate(rotate * Math.PI / 180);
context.globalAlpha = getAlpha(lifespan);
context.drawImage(
image,
-image.width / 2,
-image.height / 2,
image.width,
image.height
);
context.rotate(-rotate * Math.PI / 180);
context.scale(1 / scale, 1 / scale);
context.translate(-translateX, -translateY);
context.globalAlpha = 1;
} else {
return true;
}
};
}
stage.bubble(image, 3000, function ( lifespan ) {
// You got its lifespan, and from 1 to 0
if (lifespan >= 0) {
stage.context.drawImage(
image,
(canvas.width - image.width) / 2,
// lifespan control its positionY, so that it will look like fly up
(canvas.height - image.height) * lifespan,
image.width,
image.height
);
} else {
// Return true to free the memory
return true;
}
});
return true ?1 to 0, and go on to be negative.drawImage.return true is a flag to tell iterator to remove this handler, and stop repeating this handler again.MIT
1.0.0
FAQs
(<3kb) 💖Bubble hearts animation.
We found that bubble-hearts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.