Mouse Hover Twinkling Stars Plugin jQuery-canvas-sparkles

Add-ons
2026-08-03 13:23 4 次浏览 • 0 次下载 50.0KB
Mouse Hover Twinkling Stars Plugin jQuery-canvas-sparkles

Usage

Include the jquery and jquery-canvas-sparkles.js files in your page.

1
2
<script src="dist/jquery-canvas-sparkles.js"></script>

HTML Structure

For example, if you want to create a sparkling star effect on an image, its HTML structure looks like this:

1
2
3
<div >
<img id="image" src="demo.jpg">
</div>

Initialize the Plugin

After the page DOM elements have finished loading, initialize this jQuery star sparkle plugin using the sparkle() method.

1
$(".element").sparkle();

Configuration Parameters

The available configuration parameters for this jQuery and Canvas star sparkle plugin are:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$(document).ready(function() {
$("img").sparkle({
// Color: accepts a HEX string, the keyword "rainbow", or an array of HEX strings
color: ["#2eafea", "#e56604"],
// Number of stars displayed at once
count: 30,
// Distance from the edge of the canvas at which overlap occurs
overlap: 0,
// Set the speed
speed: 1,
// Minimum size
minSize: 4,
// Maximum size
maxSize: 7,
// Direction of star movement. Can be "up", "down", or "both"
direction: "both"
});
});

Events

The following events can be used to trigger the start, stop, and resizing of the stars.

  • start.sparkle: Triggers the stars to start sparkling.

  • stop.sparkle: Stops the star sparkle effect.

  • resize.sparkle: Dynamically changes the canvas dimensions and adjusts the positions of the stars.

For example:

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
// first we need an element with sparkles
$("header").sparkle();
// here we can remove the default mouse/keyboard triggers for sparkles,
// perhaps we don't want them to trigger on interaction
$("header")
.off("mouseover.sparkle")
.off("mouseout.sparkle")
.off("focus.sparkle")
.off("blur.sparkle")
// we can also trigger the start/stop events on the element
// which has the sparkles bound to it!
$("header")
.trigger("start.sparkle")
.on("click", function() {
$(this).trigger("stop.sparkle");
});
// it's also possible to resize teh canvas and reposition
// the sparkles whenever the browser is resized...
var timer;
$(window).on("resize", function(){
clearTimeout(timer);
timer = setTimeout(function(){
$("header").trigger("resize.sparkle");
},200);
});
星河码客

发现和分享优质开源项目,传承互联网精神,为开发者服务。

关于本站

联系我们

微信/广告合作:ITcloub (备注星河码客)

免责声明:本站资源版权归原作者所有,仅供学习与交流。如有侵权,请通过「关于我们 - 侵权投诉」联系删除。

Powered by Nuxt · Deployed on Cloudflare