sachinchoolur / lightslider

JQuery lightSlider is a lightweight responsive Content slider with carousel thumbnails navigation
http://sachinchoolur.github.io/lightslider/
MIT License
2.04k stars 1.52k forks source link

slider with links doesn't work on mobile browsers if the slider is not wide enough #161

Open Leftyx opened 9 years ago

Leftyx commented 9 years ago

I've use lightslider with images and links in each li element:

<div id="similar-employees">
    <ul class="dc-images-slider">
        <li class="similar-employee" data-src="/Content/uploads/images/239d549b-7028-4782-9df4-c61e52167b9f_thumb.jpg">
            <a href="/Home/Employee/02fa4b12-ae33-4017-959e-a43d012a424d" alt="charles dunnett">
            <img height="100" width="100" src="/Content/uploads/images/239d549b-7028-4782-9df4-c61e52167b9f_thumb.jpg?height=100&amp;width=100&amp;mode=crop" alt="Charles_Dunnet.jpg" title="">
            </a>
        </li>
        <li class="similar-employee" data-src="/Content/uploads/images/3abc3070-e19d-44cd-bc39-1a56f7d55632_thumb.jpg">
            <a href="/Home/Employee/323c36ca-787d-4e77-b3bf-a44b004dba4f" alt="james craven">
            <img height="100" width="100" src="/Content/uploads/images/3abc3070-e19d-44cd-bc39-1a56f7d55632_thumb.jpg?height=100&amp;width=100&amp;mode=crop" alt="Studio compressed.jpg" title="">
            <div class="dc-caption-small">james craven</div>
            </a>
        </li>
    </ul>
</div>

if lightslider does not contain enough images to fill the slider (arrows shown) the link href does not work. The problem is only present when using the slider on mobile device using a mobile browser like Opera.

I believe the problem sits in line 839:

changing the return value to true make things work as expected:

$slide.on('touchend', function () {
                        if (w < elSize) {
                            if (w !== 0) {
                                return true;
                            }
                        }
                        var distance;
                        if (settings.vertical === true) {
                            distance = endCoords.pageY - startCoords.pageY;
                        } else {
                            distance = endCoords.pageX - startCoords.pageX;
                        }
                        $this.touchEnd(distance);
                    });
bia2varavi commented 5 years ago

and for enable scroll on this items change touchmove to below code(change return false; to return true;), exactly function that placed on top of function that @Leftyx mentioned

$slide.on('touchmove', function (e) { if (w < elSize) { if (w !== 0) { return true; } } var orig = e.originalEvent; endCoords = orig.targetTouches[0]; var xMovement = Math.abs(endCoords.pageX - startCoords.pageX); var yMovement = Math.abs(endCoords.pageY - startCoords.pageY); if (settings.vertical === true) { if ((yMovement 3) > xMovement) { e.preventDefault(); } $this.touchMove(endCoords.pageY, startCoords.pageY); } else { if ((xMovement 3) > yMovement) { e.preventDefault(); } $this.touchMove(endCoords.pageX, startCoords.pageX); } });

marc212 commented 5 years ago

@Leftyx

Thank you so much

gobi77 commented 12 months ago

@Leftyx

I can't thank you enough for this one!

note to self: always google your issues before trying to fix them