nicolas-t / Chocolat

Chocolat : the lightbox so cool horses use it :horse:
http://chocolat.insipi.de
GNU General Public License v3.0
1.69k stars 170 forks source link

Mobile touch events like Photoswipe #25

Open dlewand691 opened 8 years ago

dlewand691 commented 8 years ago

Love the plug-in but could really use some of the touch event capability similar to Photoswipe. Any thoughts on integrating something like this? Has it been done with any examples? Thank you!

johannpinson commented 8 years ago

+1

dgobnto commented 8 years ago

+1 ;)

sam-g-roberts commented 8 years ago

+1

daslicht commented 8 years ago

+1

user928 commented 8 years ago

+1

ghost commented 8 years ago

+1

dlewand691 commented 7 years ago

This new plugin might give some inspiration on how to add mobile touch events: http://desmonding.me/zooming/

Sanabria commented 7 years ago

+1

xrat commented 7 years ago

Am I right that this issue is the cause for the fact that Chocolat is almost not usable on small mobile devices because there is no way to move the image when zoomed?

enkota commented 7 years ago

@xrat This and that you cannot swipe gesture to the next slide easily.

shangul commented 7 years ago

+1

nicolas-t commented 7 years ago

More informations regarding swipe, and how it can be done : https://github.com/nicolas-t/Chocolat/issues/68

yannicgraeser commented 7 years ago

Am I right that this issue is the cause for the fact that Chocolat is almost not usable on small mobile devices because there is no way to move the image when zoomed?

I can't use this otherwise very cool plugin because of this :(

isospin commented 6 years ago

+1

johansmitsnl commented 5 years ago

This is my piece of code inspired by the comments:

$(document).ready(function () {
    $('.chocolat-parent').Chocolat({
        imageSize: 'contain',
        loop: true,
        enableZoom: false,
        afterImageLoad: function () {
            const chocolat = this;
            const hammertime = new Hammer(this.elems.img[0], {});
            hammertime.on('pan', function (ev) {
                if (ev.isFinal) {

                   // FIXME needs proper API for calling the zoom function (does not work properly)
                    chocolat.zoomOut();

                    if (ev.additionalEvent === 'panleft') {
                        chocolat.api().prev();
                    } else if (ev.additionalEvent === 'panright') {
                        chocolat.api().next();
                    }
                }
            });
            hammertime.on('doubletap', function (ev) {
                if (ev.isFinal) {
                    // FIXME needs proper API for calling the zoom function (does not work properly)
                    chocolat.zoomIn({pageX: ev.center.x, pageY: ev.center.y});
                }
            });
        }
    });
});

The only part missing is the Zoom implementation. It seems the API does not have zoom exposed and this implementation does not work. Suggestions?

Agree with @nicolas-t to not implement zoom because it is easy to implement with the library os choice.

nicolas-t commented 5 years ago

@johansmitsnl You could totally add zoom methods to the api. A pull request would be very welcome.

At this line :
https://github.com/nicolas-t/Chocolat/blob/master/src/js/jquery.chocolat.js#L663

Something like :

zoomIn: function(e) {
    return that.zoomIn(e)
},

zoomOut: function(duration) {
    return that.zoomOut(duration)
},

Then you would have to call it like this :

            hammertime.on('doubletap', function (ev) {
                if (ev.isFinal) {
                    chocolat.api().zoomIn(ev.srcEvent); // pass source event ev.srcEvent
                }
            });