Saturday, 8 September 2018

BXSlider 4 fullscreen on mobile devices: How to keep native vertical page scroll (up, down) but keep horizontal touch functionality (left,right)?

The following snippet should demonstrate the problem quite well:

(function ($) {

    $('.bxslider').each(function() {
        var bxid = $(this).attr("data-bxid");

        var bx = $(this).bxSlider({
            auto: false,
            autoStart: false
        });
    });

})(jQuery);
/* Styles */
#before, #after {
  width:350px;
  height:350px;
  background-color:#ccf;
}

/* BXSlider */
.bx-wrapper {
  position: relative;
  margin-bottom: 60px;
  padding: 0;
  *zoom: 1;
  -ms-touch-action: pan-y;
  touch-action: pan-y;
}

.bx-wrapper img {
  max-width: 100%;
  display: block;
}

.bxslider {
  background-color:#eee;
  margin: 0;
  padding: 0;
  /*fix flickering when used background-image instead of <img> (on Chrome)*/
  -webkit-perspective: 1000;
}

ul.bxslider {
  list-style: none;
  width:100%;
}

ul.bxslider li {
   width:100%;
}

.bx-viewport {
  /* fix other elements on the page moving (in Chrome) */
  -webkit-transform: translateZ(0);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bxslider/4.2.15/jquery.bxslider.min.js"></script>
<div id="before"></div>
<ul class="bxslider">
<li><p>If you touch me vertically ...<img src="https://via.placeholder.com/500x350"></li>
<li>... I want to scroll down normally ...<img src="https://via.placeholder.com/500x250"></li>
<li>... but nothing happens 😭<img src="https://via.placeholder.com/500x450"></li>
</ul>
<div id="after"></div>

In the developer tools of your browser window try to scroll down by touch within the running code snippet - it is not possible. However this is not an option as with a fullscreen horizontal bxSlider visitors are loosing the ability to browser the site completely - unacceptable!

bxSlider provides the following setting:

touchEnabled:false

However this is also not an option, because smartphone visitors really should be able to switch slides to the right/to the left with their fingers.

Therefore I need a possibility such that:

  • HORIZONTAL touch move: Go smoothly to the next/previous slide within the slider.
  • VERTICAL touch move: Just keep the normal scrolling of the viewport within the browser.

Unfortunatly I did not find any combinations of bxslider settings how to achieve this yet. Do you know a solution for this (preferrably without modifying the bxslider core file itself)?



from BXSlider 4 fullscreen on mobile devices: How to keep native vertical page scroll (up, down) but keep horizontal touch functionality (left,right)?

No comments:

Post a Comment