fcarriedo / jquery-blink Goto Github PK
View Code? Open in Web Editor NEWYet another blink plugin for jquery
Home Page: https://fcarriedo.github.io/jquery-blink/
License: MIT License
Yet another blink plugin for jquery
Home Page: https://fcarriedo.github.io/jquery-blink/
License: MIT License
Change 'null' to 'undefined' on unset settings as it may better represent it. See: http://bonsaiden.github.com/JavaScript-Garden/#undefined
The onMaxBlinks
callback fires one blink before maxBlinks
.
It would be nice to have a cancel function something like this:
(function( $ ) {
var timeout;
$.fn.blink = function( options ) {
var settings = {
maxBlinks : undefined,
blinkPeriod : 1000,
onMaxBlinks : function() {},
onBlink : function(i) {},
speed : undefined
};
if(options) {
$.extend(settings, options);
}
var blinkElem = this;
var on = true;
var blinkCount = 0;
settings.speed = settings.speed ? settings.speed : settings.blinkPeriod/2;
/* The function that does the actual fading. */
(function toggleFade() {
var maxBlinksReached = false;
if(on){
blinkElem.fadeTo(settings.speed, 0.01);
} else {
blinkCount++;
maxBlinksReached = (settings.maxBlinks && (blinkCount >= settings.maxBlinks));
blinkElem.fadeTo(settings.speed, 1, function() {
settings.onBlink.call(blinkElem, blinkCount);
if(maxBlinksReached) {
settings.onMaxBlinks.call();
}
});
}
on = !on;
if(!maxBlinksReached) {
timeout = setTimeout(toggleFade, settings.blinkPeriod/2); // #3
}
})();
return this; // Returning 'this' to maintain chainability.
};
$.fn.blinkCancel = function() {
clearTimeout(timeout)
this.fadeTo(0, 1)
return this;
}
})(jQuery);
Change implementation to use 'setTimeout' instead of 'setInterval'. Best practice to to prevent methods calls stacking up. See: http://bonsaiden.github.com/JavaScript-Garden/#timeouts
The fist blink waits for half a period before starting (because the setInterval() behavior). It should start with the first blink right away.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.