Created
August 8, 2018 09:14
-
-
Save hasinhayder/4c1be1941ad2d03b839984e27a8670cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(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