Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable vertical scrolling on touch device while using owl carousel

when dragging horizontal carousel left to right on touch device it also allows it to be dragged up and down which jiggles the whole page around. How can I disable vertical scrolling on owl carousel. I can post the js file if anyone can help

Thanks in advance

like image 861
in00b Avatar asked Apr 02 '17 00:04

in00b


People also ask

How do I stop my owl carousel from scrolling?

carousel', function(event) { $('body'). css('overflow', 'auto'); }); So; it use css overflow to disable scrolling when dragging started and enables it back when it finished. Save this answer.

How do I stop vertical scrolling?

To hide the vertical scrollbar and prevent vertical scrolling, use overflow-y: hidden like so: HTML.

What is horizontal and vertical scrolling?

A horizontal scroll bar enables the user to scroll the content of a window to the left or right. A vertical scroll bar enables the user to scroll the content up or down.


2 Answers

Awesome css3 :)

.owl-carousel
{
    -ms-touch-action: pan-y;
    touch-action: pan-y;
}
like image 126
Yasin UYSAL Avatar answered Sep 30 '22 16:09

Yasin UYSAL


This seems to work for me, at least on iOS, haven't tested on Android.

When you start sliding with mouse or touch I saw that Owl Carousel adds the class .owl-grab to the slider. I then found this code from @Turnerj and just put .owl-grab in the code.

Disable scrolling when touch moving certain element

It also works with multiple sliders on same page. Hope this helps! (I'm new to jQuery so there could probably be flaws to this solution)

window.blockMenuHeaderScroll = false;
$(window).on('touchstart', function(e) {
    if ($(e.target).closest('.owl-grab').length == 1) {
        blockMenuHeaderScroll = true;
    }
});
$(window).on('touchend', function() {
    blockMenuHeaderScroll = false;
});
$(window).on('touchmove', function(e) {
     if (blockMenuHeaderScroll) {
        e.preventDefault();
     }
});
like image 33
learningbydoing Avatar answered Sep 30 '22 17:09

learningbydoing