Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal swipe gesture and vertical page scroll

I am building a mobile site and I have a slide show of images that allows sliding through images horizontally. The javascript library I'm using is bxslider. However, if one touches the slide show and wants to scroll the page up/down, the slide show blocks vertical scrolling and hence another section of the site must be touched.

Could someone please tell me how I could keep vertical scroll enabled (i.e, not allow the slideshow to block the normal scroll?)

Thanks!

like image 800
Sorin Cioban Avatar asked Feb 05 '13 14:02

Sorin Cioban


People also ask

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.

Is horizontal or vertical scrolling better?

Horizontal scrolling saves a lot of vertical screen space. Rather than displaying all the content at once on a very long page, horizontal layouts introduce users to smaller chunks of information. The layout is much more flexible. One can add content in both directions — vertical and horizontal.

What is horizontal scroll used for?

Horizontal scrolling is a one-page navigation method designers can use. In this method, users can use different functionalities on a page to scroll right or left, to see more information within the container or window. Users scroll horizontally by clicking on a scroll bar and dragging it with their mouse or finger.


1 Answers

Try this, Change the onTouchMove fn in the bxslider library to this

        var onTouchMove = function (e) {
        if (slider.settings.mode != 'fade') {
            var orig = e.originalEvent;
            var value = 0;
            // if horizontal, drag along x axis
            if (slider.settings.mode == 'horizontal')
            {   
                var hchange = orig.changedTouches[0].pageX - slider.touch.start.x;
                var vchange = orig.changedTouches[0].pageY - slider.touch.start.y;

                if(Math.abs(hchange)>20 && Math.abs(hchange)>Math.abs(vchange))
                {   
                    value = slider.touch.originalPos.left + hchange;
                    setPositionProperty(value, 'reset', 0);
                    e.preventDefault();
                }
                // if vertical, drag along y axis
            } else{
                e.preventDefault();
                var change = orig.changedTouches[0].pageY - slider.touch.start.y;
                value = slider.touch.originalPos.top + change;
                setPositionProperty(value, 'reset', 0);
            }

        }
    }
like image 77
Bhadra Avatar answered Oct 26 '22 16:10

Bhadra