Skip to content

Instantly share code, notes, and snippets.

@lucypero
Created September 14, 2017 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucypero/0959ff1ad71d1e2b6f2a018603b20788 to your computer and use it in GitHub Desktop.
Save lucypero/0959ff1ad71d1e2b6f2a018603b20788 to your computer and use it in GitHub Desktop.
Loading dots Plugin by cssTricks
/*loading dots plugin https://css-tricks.com/loading-dots-plugin/*/
(function ($) {
$.Loadingdotdotdot = function (el, options) {
var base = this;
base.$el = $(el);
base.$el.data("Loadingdotdotdot", base);
base.dotItUp = function ($element, maxDots) {
if ($element.text().length == maxDots) {
$element.text("");
} else {
$element.append(".");
}
};
base.stopInterval = function () {
clearInterval(base.theInterval);
};
var speed, maxDots;
base.init = function () {
if (typeof speed === "undefined" || speed === null) speed = 300;
if (typeof maxDots === "undefined" || maxDots === null) maxDots = 3;
base.speed = speed;
base.maxDots = maxDots;
base.options = $.extend({}, $.Loadingdotdotdot.defaultOptions, options);
base.$el.html("<span>" + base.options.word + "<em>...</em></span>");
base.$dots = base.$el.find("em");
base.$loadingText = base.$el.find("span");
base.theInterval = setInterval(base.dotItUp, base.options.speed, base.$dots, base.options.maxDots);
};
base.init();
};
$.Loadingdotdotdot.defaultOptions = {
speed: 300,
maxDots: 3,
word: "Loading"
};
$.fn.Loadingdotdotdot = function (options) {
if (typeof options == "string") {
var safeGuard = $(this).data('Loadingdotdotdot');
if (safeGuard) {
safeGuard.stopInterval();
}
} else {
return this.each(function () {
new $.Loadingdotdotdot(this, options);
});
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment