Skip to content

Instantly share code, notes, and snippets.

@hasinhayder
Created August 8, 2018 09:14
Show Gist options
  • Save hasinhayder/4c1be1941ad2d03b839984e27a8670cf to your computer and use it in GitHub Desktop.
Save hasinhayder/4c1be1941ad2d03b839984e27a8670cf to your computer and use it in GitHub Desktop.
;(function($){
$.fn["minitoggle"] = function(options) {
options = options || {};
opts = $.extend({
on: false
}, options);
doToggle = function(toggle) {
toggle = toggle.find(".minitoggle");
active = toggle.toggleClass("active").hasClass("active");
handle = toggle.find(".toggle-handle");
handlePosition = handle.position()
offset = (active ? toggle.width() - handle.width() - handlePosition.left * 2 : 0);
handle.css({
transform: "translate3d(" + offset + "px,0,0)",
});
return toggle.trigger({
type: "toggle",
isActive: active
});
};
this.each(function() {
var self = $(this);
self.html("<div class=\"minitoggle\"><div class=\"toggle-handle\"></div></div>");
self.click(function() {
doToggle(self);
});
if (opts["on"]) {
doToggle(self);
}
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment