Browse Source

Fixing the toogle offset.

pull/210/head
connors 12 years ago
parent
commit
6fe8ad9ee8
  1. 2
      dist/ratchet.css
  2. 9
      dist/ratchet.js
  3. 2
      lib/css/toggles.css
  4. 9
      lib/js/toggles.js

2
dist/ratchet.css vendored

@ -1137,6 +1137,8 @@ button.button-block {
/* Active state for toggle handle */ /* Active state for toggle handle */
.toggle.active .toggle-handle { .toggle.active .toggle-handle {
border-color: #4cd964; border-color: #4cd964;
-webkit-transform: translate3d(17px,0,0);
transform: translate3d(17px,0,0);
}/* Push styles (to be used with push.js) }/* Push styles (to be used with push.js)
-------------------------------------------------- */ -------------------------------------------------- */

9
dist/ratchet.js vendored

@ -701,13 +701,10 @@
var handle = toggle.querySelector('.toggle-handle'); var handle = toggle.querySelector('.toggle-handle');
var toggleWidth = toggle.offsetWidth; var toggleWidth = toggle.offsetWidth;
var handleWidth = handle.offsetWidth; var handleWidth = handle.offsetWidth;
var offset = toggle.classList.contains('active') ? toggleWidth - handleWidth : 0; var offset = toggle.classList.contains('active') ? (toggleWidth - handleWidth) - 2 : 0;
start = { pageX : e.touches[0].pageX - offset, pageY : e.touches[0].pageY }; start = { pageX : e.touches[0].pageX - offset, pageY : e.touches[0].pageY };
touchMove = false; touchMove = false;
// todo: probably should be moved to the css
toggle.style['-webkit-transition-duration'] = 0;
}); });
window.addEventListener('touchmove', function (e) { window.addEventListener('touchmove', function (e) {
@ -721,7 +718,7 @@
var current = e.touches[0]; var current = e.touches[0];
var toggleWidth = toggle.offsetWidth; var toggleWidth = toggle.offsetWidth;
var handleWidth = handle.offsetWidth; var handleWidth = handle.offsetWidth;
var offset = toggleWidth - handleWidth; var offset = (toggleWidth - handleWidth) - 2;
touchMove = true; touchMove = true;
distanceX = current.pageX - start.pageX; distanceX = current.pageX - start.pageX;
@ -744,7 +741,7 @@
var handle = toggle.querySelector('.toggle-handle'); var handle = toggle.querySelector('.toggle-handle');
var toggleWidth = toggle.offsetWidth; var toggleWidth = toggle.offsetWidth;
var handleWidth = handle.offsetWidth; var handleWidth = handle.offsetWidth;
var offset = toggleWidth - handleWidth; var offset = (toggleWidth - handleWidth) - 2;
var slideOn = (!touchMove && !toggle.classList.contains('active')) || (touchMove && (distanceX > (toggleWidth/2 - handleWidth/2))); var slideOn = (!touchMove && !toggle.classList.contains('active')) || (touchMove && (distanceX > (toggleWidth/2 - handleWidth/2)));
if (slideOn) handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'; if (slideOn) handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)';

2
lib/css/toggles.css

@ -35,4 +35,6 @@
/* Active state for toggle handle */ /* Active state for toggle handle */
.toggle.active .toggle-handle { .toggle.active .toggle-handle {
border-color: #4cd964; border-color: #4cd964;
-webkit-transform: translate3d(17px,0,0);
transform: translate3d(17px,0,0);
} }

9
lib/js/toggles.js

@ -28,13 +28,10 @@
var handle = toggle.querySelector('.toggle-handle'); var handle = toggle.querySelector('.toggle-handle');
var toggleWidth = toggle.offsetWidth; var toggleWidth = toggle.offsetWidth;
var handleWidth = handle.offsetWidth; var handleWidth = handle.offsetWidth;
var offset = toggle.classList.contains('active') ? toggleWidth - handleWidth : 0; var offset = toggle.classList.contains('active') ? (toggleWidth - handleWidth) - 2 : 0;
start = { pageX : e.touches[0].pageX - offset, pageY : e.touches[0].pageY }; start = { pageX : e.touches[0].pageX - offset, pageY : e.touches[0].pageY };
touchMove = false; touchMove = false;
// todo: probably should be moved to the css
toggle.style['-webkit-transition-duration'] = 0;
}); });
window.addEventListener('touchmove', function (e) { window.addEventListener('touchmove', function (e) {
@ -48,7 +45,7 @@
var current = e.touches[0]; var current = e.touches[0];
var toggleWidth = toggle.offsetWidth; var toggleWidth = toggle.offsetWidth;
var handleWidth = handle.offsetWidth; var handleWidth = handle.offsetWidth;
var offset = toggleWidth - handleWidth; var offset = (toggleWidth - handleWidth) - 2;
touchMove = true; touchMove = true;
distanceX = current.pageX - start.pageX; distanceX = current.pageX - start.pageX;
@ -71,7 +68,7 @@
var handle = toggle.querySelector('.toggle-handle'); var handle = toggle.querySelector('.toggle-handle');
var toggleWidth = toggle.offsetWidth; var toggleWidth = toggle.offsetWidth;
var handleWidth = handle.offsetWidth; var handleWidth = handle.offsetWidth;
var offset = toggleWidth - handleWidth; var offset = (toggleWidth - handleWidth) - 2;
var slideOn = (!touchMove && !toggle.classList.contains('active')) || (touchMove && (distanceX > (toggleWidth/2 - handleWidth/2))); var slideOn = (!touchMove && !toggle.classList.contains('active')) || (touchMove && (distanceX > (toggleWidth/2 - handleWidth/2)));
if (slideOn) handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)'; if (slideOn) handle.style.webkitTransform = 'translate3d(' + offset + 'px,0,0)';

Loading…
Cancel
Save