mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 15:07:13 +08:00
Fixed offset bug in slidebox
Sometimes the slidebox would get out of whack, it was a timing issue with requestAnimationFrame
This commit is contained in:
15
dist/js/ionic.js
vendored
15
dist/js/ionic.js
vendored
@ -2297,6 +2297,7 @@ window.ionic = {
|
|||||||
},
|
},
|
||||||
_startDrag: function(e) {
|
_startDrag: function(e) {
|
||||||
var offsetX, content;
|
var offsetX, content;
|
||||||
|
console.log("START");
|
||||||
|
|
||||||
this._initDrag();
|
this._initDrag();
|
||||||
|
|
||||||
@ -2320,18 +2321,20 @@ window.ionic = {
|
|||||||
|
|
||||||
_handleEndDrag: function(e) {
|
_handleEndDrag: function(e) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
console.log("END");
|
||||||
|
|
||||||
var finalOffsetX, content, ratio, slideWidth, totalWidth, offsetX;
|
var finalOffsetX, content, ratio, slideWidth, totalWidth, offsetX;
|
||||||
|
window.requestAnimationFrame(function() {
|
||||||
|
|
||||||
// We didn't have a drag, so just init and leave
|
// We didn't have a drag, so just init and leave
|
||||||
if(!this._currentDrag) {
|
if(!_this._currentDrag) {
|
||||||
this._initDrag();
|
_this._initDrag();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Snap to the correct spot
|
// Snap to the correct spot
|
||||||
|
|
||||||
content = this._currentDrag.content;
|
content = _this._currentDrag.content;
|
||||||
|
|
||||||
// Enable transition duration
|
// Enable transition duration
|
||||||
content.classList.add('slide-box-animating');
|
content.classList.add('slide-box-animating');
|
||||||
@ -2356,13 +2359,15 @@ window.ionic = {
|
|||||||
// Negative offsetX to slide correctly
|
// Negative offsetX to slide correctly
|
||||||
content.style.webkitTransform = 'translate3d(' + -finalOffsetX + 'px, 0, 0)';
|
content.style.webkitTransform = 'translate3d(' + -finalOffsetX + 'px, 0, 0)';
|
||||||
|
|
||||||
this._initDrag();
|
_this._initDrag();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Process the drag event to move the item to the left or right.
|
* Process the drag event to move the item to the left or right.
|
||||||
*/
|
*/
|
||||||
_handleDrag: function(e) {
|
_handleDrag: function(e) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
console.log("DRAG");
|
||||||
window.requestAnimationFrame(function() {
|
window.requestAnimationFrame(function() {
|
||||||
var content;
|
var content;
|
||||||
|
|
||||||
@ -2383,7 +2388,7 @@ window.ionic = {
|
|||||||
content = _this._currentDrag.content;
|
content = _this._currentDrag.content;
|
||||||
|
|
||||||
// Grab the new X point, capping it at zero
|
// Grab the new X point, capping it at zero
|
||||||
var newX = Math.min(content.offsetWidth, _this._currentDrag.startOffsetX + e.gesture.deltaX);
|
var newX = Math.min(0, _this._currentDrag.startOffsetX + e.gesture.deltaX);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
var rightMostX = -(content.offsetWidth * Math.max(0, content.children.length - 1));
|
var rightMostX = -(content.offsetWidth * Math.max(0, content.children.length - 1));
|
||||||
|
|||||||
@ -31,6 +31,7 @@
|
|||||||
},
|
},
|
||||||
_startDrag: function(e) {
|
_startDrag: function(e) {
|
||||||
var offsetX, content;
|
var offsetX, content;
|
||||||
|
console.log("START");
|
||||||
|
|
||||||
this._initDrag();
|
this._initDrag();
|
||||||
|
|
||||||
@ -54,18 +55,20 @@
|
|||||||
|
|
||||||
_handleEndDrag: function(e) {
|
_handleEndDrag: function(e) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
console.log("END");
|
||||||
|
|
||||||
var finalOffsetX, content, ratio, slideWidth, totalWidth, offsetX;
|
var finalOffsetX, content, ratio, slideWidth, totalWidth, offsetX;
|
||||||
|
window.requestAnimationFrame(function() {
|
||||||
|
|
||||||
// We didn't have a drag, so just init and leave
|
// We didn't have a drag, so just init and leave
|
||||||
if(!this._currentDrag) {
|
if(!_this._currentDrag) {
|
||||||
this._initDrag();
|
_this._initDrag();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Snap to the correct spot
|
// Snap to the correct spot
|
||||||
|
|
||||||
content = this._currentDrag.content;
|
content = _this._currentDrag.content;
|
||||||
|
|
||||||
// Enable transition duration
|
// Enable transition duration
|
||||||
content.classList.add('slide-box-animating');
|
content.classList.add('slide-box-animating');
|
||||||
@ -90,13 +93,15 @@
|
|||||||
// Negative offsetX to slide correctly
|
// Negative offsetX to slide correctly
|
||||||
content.style.webkitTransform = 'translate3d(' + -finalOffsetX + 'px, 0, 0)';
|
content.style.webkitTransform = 'translate3d(' + -finalOffsetX + 'px, 0, 0)';
|
||||||
|
|
||||||
this._initDrag();
|
_this._initDrag();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Process the drag event to move the item to the left or right.
|
* Process the drag event to move the item to the left or right.
|
||||||
*/
|
*/
|
||||||
_handleDrag: function(e) {
|
_handleDrag: function(e) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
console.log("DRAG");
|
||||||
window.requestAnimationFrame(function() {
|
window.requestAnimationFrame(function() {
|
||||||
var content;
|
var content;
|
||||||
|
|
||||||
@ -117,7 +122,7 @@
|
|||||||
content = _this._currentDrag.content;
|
content = _this._currentDrag.content;
|
||||||
|
|
||||||
// Grab the new X point, capping it at zero
|
// Grab the new X point, capping it at zero
|
||||||
var newX = Math.min(content.offsetWidth, _this._currentDrag.startOffsetX + e.gesture.deltaX);
|
var newX = Math.min(0, _this._currentDrag.startOffsetX + e.gesture.deltaX);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
var rightMostX = -(content.offsetWidth * Math.max(0, content.children.length - 1));
|
var rightMostX = -(content.offsetWidth * Math.max(0, content.children.length - 1));
|
||||||
|
|||||||
Reference in New Issue
Block a user