0

I'm messing around with hammer.js and want to swipe 100 images that are stacked on one another. Basically, like a stack of cards. I'm having trouble targeting the child element of the #wrap and why my swipe animation has such huge lag after it has been swiped.

Below is the html and js.

html:

    <body>
    <div id="wrap">
    <div class="bioImg">
        <img src="imgs/1.jpg" alt="biography image">
    </div>
    <div class="bioImg">
            <img src="imgs/2.jpg" alt="biography image">
    </div>
    <div class="bioImg">
        <img src="imgs/3.jpg" alt="biography image">
    </div>
    <div class="bioImg">
        <img src="imgs/4.jpg" alt="biography image">
    </div>
    <div class="bioImg">
        <img src="imgs/5.jpg" alt="biography image">
    </div>
    <div class="bioImg">
        <img src="imgs/6.jpg" alt="biography image">
    </div>
    <div class="bioImg">
        <img src="imgs/7.jpg" alt="biography image">
    </div>
    <div class="bioImg">
        <img src="imgs/8.jpg" alt="biography image">
    </div>
    </div>
    </body>

JS:

// Create a manager to manager the element
var hamMangr = new Hammer.Manager(wrap);

// Create a recognizer
var Swipe = new Hammer.Swipe();

// Add the recognizer to the manager
hamMangr.add(Swipe, { direction: Hammer.DIRECTION_HORIZONTAL });

hamMangr.on('swipeup swiperight swipedown swipeleft', function (e) {
    console.log(e);
    console.log(e.target);
    console.log(e.type);
    tl.add(slideOutAnim(e.target, e.type, 1))
});
2
  • Ahh, I figured out the problem I was having. The lag issue was the image's file size were to large for mobile. Silly mistake. To target the children of #wrap, can't use e.target to drill down. Used the HamMangr constructor to find #wrap child element. Hope this helps someone else. Here is a codepen. Commented Jan 3, 2018 at 17:31
  • Another note. I was still having problems with the animation after the swipe. After the swipe the animation would skip frames until it got down to a low count of images. I found this to be very helpful from @Simon Boudrias. After deleting box-shadow and radial gradients on each image, animation was smooth. Added a solid pixel border in replacement of the shadow. Hope this helps someone. Commented Jan 4, 2018 at 16:31

0

Browse other questions tagged or ask your own question.