-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enabling Mobile Support #101
Comments
Hi action-simon! I don't have an iPad, but I think just touching the outer panels or the arrows would change the slide. Or do you mean you'd like swipe support? |
Hello! Yes I am taking about the swipe support. Touching the arrows or the outer areas does work of course ;) |
Ok, I'll look into making a demo for you soon... I have other distractions today =( |
Oh many thanks in advance! Very nice from you. |
Ok, here is a demo of swipe support... it's a bit of code, but all you need to do is include it inside of a document ready event with the correct jQuery(function($){
$('#slider').movingBoxes({
startPanel: 4,
wrap: true,
buildNav: true,
navFormatter: function(index, panel) {
return "●";
}
});
/* Add Swipe to Moving Boxes */
var target = $('#slider'),
// allow movement if < 1000 ms (1 sec)
maxTime = 1000,
// swipe movement of 50 pixels triggers the swipe
maxDistance = 50,
api = target.data('movingBoxes'),
startX = 0,
startTime = 0,
touch = "ontouchend" in document,
startEvent = (touch) ? 'touchstart' : 'mousedown',
moveEvent = (touch) ? 'touchmove' : 'mousemove',
endEvent = (touch) ? 'touchend' : 'mouseup';
api.$wrap.on(startEvent, function(e) {
// prevent image drag (Firefox)
e.preventDefault();
startTime = e.timeStamp;
startX = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX;
})
.on(endEvent, function(e) {
startTime = 0;
startX = 0;
})
.on(moveEvent, function(e) {
e.preventDefault();
var currentX = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX,
currentDistance = (startX === 0) ? 0 : Math.abs(currentX - startX),
// allow if movement < 1 sec
currentTime = e.timeStamp;
if (startTime !== 0 && currentTime - startTime < maxTime && currentDistance > maxDistance) {
if (currentX < startX) {
// swipe left code here
api.goForward();
}
if (currentX > startX) {
// swipe right code here
api.goBack();
}
startTime = 0;
startX = 0;
}
});
}); If you are using an older version of jQuery (before v1.7), then replace the |
Oh thank you so much!! Very nice support from you, I have to say. |
Hello. It is me again. Finally I had time to implement it on the site, but now I have the problem that only Swipe is working on the Movingbox with the ipad. If i click on the non active slides or the nav arrows or thumbnails nothing happens. On PC it is still working. Edit: It is the same issue on the demo you have posted as well just to be sure it is not on my end ;) It seems that all href links are not working. (Within slider div) |
Try changing the |
Oh wow. Many thanks. It is working like a charm now. Edit: Links are working on the Thumbnails and arrows now. But still not on the Slides itself.
|
LOL ok, lets go one more level deep... change the code to |
Nope. I'm afraid thats not working. Maybe it is useful posting the complete js? function fnIsAppleMobile() {
if (navigator && navigator.userAgent && navigator.userAgent != null) {
var strUserAgent = navigator.userAgent.toLowerCase();
var arrMatches = strUserAgent.match(/(iphone|ipod|ipad|android)/);
if (arrMatches)
return true;
}
// End if (navigator && navigator.userAgent)
return false;
}
jQuery(function($){
$('#slider').movingBoxes({
startPanel: 4,
reducedSize: 0.9,
initAnimation: true,
hashTags: false,
wrap: true,
buildNav: true,
speed: 500,
stopAnimation: true,
fixedHeight: true,
easing: 'easeOutBack',
navFormatter: function(index, panel) {
return "●";
}
preinit: function(e, mb, tar) {
if (fnIsAppleMobile() == false) {
var throttled = false,
throttledDelay = 200;
mb.$window.mousewheel(function(event, delta) {
if (!throttled) {
mb.change(mb.curPanel + (delta < 0 ? 1: -1));
throttled = true;
setTimeout(function() {
throttled = false;
}, throttledDelay);
}
return false;
});
}
}
});
if (fnIsAppleMobile() == true) {
/* Add Swipe to Moving Boxes only when the user Agent is an Smartphone */
var target = $('#slider'),
// allow movement if < 1000 ms (1 sec)
maxTime = 1000,
// swipe movement of 50 pixels triggers the swipe
maxDistance = 50,
api = target.data('movingBoxes'),
startX = 0,
startTime = 0,
touch = "ontouchend" in document,
startEvent = (touch) ? 'touchstart': 'mousedown',
moveEvent = (touch) ? 'touchmove': 'mousemove',
endEvent = (touch) ? 'touchend': 'mouseup';
api.$panels.on(startEvent, function(e) {
// prevent image drag (Firefox)
e.preventDefault();
startTime = e.timeStamp;
startX = e.originalEvent.touches ? e.originalEvent.touches[0].pageX: e.pageX;
}).on(endEvent, function(e) {
startTime = 0;
startX = 0;
}).on(moveEvent, function(e) {
e.preventDefault();
var currentX = e.originalEvent.touches ? e.originalEvent.touches[0].pageX: e.pageX,
currentDistance = (startX === 0) ? 0: Math.abs(currentX - startX),
// allow if movement < 1 sec
currentTime = e.timeStamp;
if (startTime !== 0 && currentTime - startTime < maxTime && currentDistance > maxDistance) {
if (currentX < startX) {
// swipe left code here
api.goForward();
}
if (currentX > startX) {
// swipe right code here
api.goBack();
}
startTime = 0;
startX = 0;
}
});
} else {
// Disable Image Dragging
$("#slider img").mousedown(function() {
return false;
});
};
}); |
I think that code is just missing a comma before the },
preinit: function(e, mb, tar) { |
Sorry for the delay but I was busy. ;) I had already this comma in my JS. Maybe I made a mistake copy/pasting the code in here. So sadly it is still not working. Oh and the links are only clickable on the arrows and thumbnails. So the links next to the active slide are not working as well. |
Well, all I can think of is to remove the |
Oh many thanks! Finally it is working like I want. Thank you very much. :) |
Hello.
I am using MovingBoxes which I really love.
But I run into a issue and want to ask if it's possible to enable Mobile/Touchpad Support for Mobile Devices like the iPad, iPhone or Android Phones.
I mean that you can slide the images with your finger on this devices.
The text was updated successfully, but these errors were encountered: