switchery
switchery copied to clipboard
Switchery to be even usable needs drag support. come on now
it makes zero sense that u would make a replica of the iOS7 switch without the drag feature. come on now. It's totally possible. transforms (i.e. translateX) should have been used rather than transitions.
Tell me your recommended way to implement this, and I'll do it and submit a pull request.
+1
Yes, this would be nice.
+1 - our users are getting tripped up, thinking they can drag the switch over, not realizing it can only be tapped. An upgrade here would be amazing!
+1
+1
+1
Nothing changed here... someone able to add this feature on his own?
With jQuery, I've added this feature as follows:
//Switchery initialization
var init = new Switchery(document.querySelector('.js-switch'));
setTimeout(function () {
var _self = $(".switchery"),
startPos = { x: 0, y: 0 },
currentPos = { x: 0, y: 0 };
var el=_self.find("small").get(0);
el.addEventListener('touchstart', function (event) {
startPos = { x: event.changedTouches[0].pageX, y: event.changedTouches[0].pageY };
}, false);
el.addEventListener('touchmove', function (event) {
event.preventDefault();
currentPos = { x: event.changedTouches[0].pageX, y: event.changedTouches[0].pageY };
}, false);
el.addEventListener('touchend', function (event) {
currentPos = { x: event.changedTouches[0].pageX, y: event.changedTouches[0].pageY };
if (currentPos.x != startPos.x){
_self.trigger("click");//here is the key hack!
}
startPos = { x: 0, y: 0 },
currentPos = { x: 0, y: 0 };
}, false);
}, 1000);
@nelsonkuang Thanks, but what if I have multiple switches on a page?
@nelsonkuang Snippet looks good, could you make a PR?