flipsnap.js

Demo

simple

1
2
3

show code

Flipsnap('.flipsnap');

img

img
img
img

show code

Flipsnap('.flipsnap');

distance

1
2
3
4
5

show code

Flipsnap('.flipsnap', {
    distance: 230
});

maxPoint

1
2
3
4
5
6
7
8
9
10

show code

Flipsnap('.flipsnap', {
    distance: 160, // 80px * 2
    maxPoint: 3    // move able 3 times
});

transitionDuration

1
2
3
4
5

show code

Flipsnap('.flipsnap', {
    distance: 230,
    transitionDuration: 1000
});

pointmove

1
2
3
4
5

show code

var $pointer = $('.pointer span');
var flipsnap = Flipsnap('.flipsnap', {
    distance: 230
});
flipsnap.element.addEventListener('fspointmove', function() {
    $pointer.filter('.current').removeClass('current');
    $pointer.eq(flipsnap.currentPoint).addClass('current');
}, false);

refresh

1

show code

var $flipsnap = $('.flipsnap');
var distance = 230;
var padding = 30;
var flipsnap = Flipsnap(".flipsnap", {
    distance: distance
});
var width = distance + padding;

// append new item
$(".add").click(function() {
    var newNumber = $flipsnap.find(".item").size() + 1;
    var $item = $("<div>").addClass("item").text(newNumber);
    width += distance;
    $flipsnap.append($item).width(width);
    flipsnap.refresh();
});

// remove last item
$(".remove").click(function() {
    var $items = $flipsnap.find(".item");
    if ($items.size() <= 1) return;
    width -= distance;
    $items.last().remove().width(width);
    flipsnap.refresh();
});

next, prev

1
2
3

show code

var flipsnap = Flipsnap('.flipsnap', {
    distance: 230
});
var $next = $('.next').click(function() {
    flipsnap.toNext();
});
var $prev = $('.prev').click(function() {
    flipsnap.toPrev();
});
flipsnap.element.addEventListener('fspointmove', function() {
    $next.attr('disabled', !flipsnap.hasNext());
    $prev.attr('disabled', !flipsnap.hasPrev());
}, false);

moveToPoint

1
2
3
4
5
6
7
8
9
10

show code

var flipsnap = Flipsnap('.flipsnap', {
    distance: 230
});
var $num = $('input.num');
$('button.go').click(function() {
    flipsnap.moveToPoint($num.val() - 1);
});

disableTouch

1
2
3
4
5

show code

var flipsnap = Flipsnap('.flipsnap', {
    distance: 230,
    disableTouch: true
});

// disable check
$('.isDisable').change(function() {
    flipsnap.disableTouch = $(this).is(':checked');
});

// Go btn
var $num = $('input.num');
$('button.go').click(function() {
    flipsnap.moveToPoint($num.val() - 1);
});

// next, prev btn
var $next = $('.next').click(function() {
    flipsnap.toNext();
});
var $prev = $('.prev').click(function() {
    flipsnap.toPrev();
});
flipsnap.element.addEventListener('fspointmove', function() {
    $next.attr('disabled', !flipsnap.hasNext());
    $prev.attr('disabled', !flipsnap.hasPrev());
}, false);

touch events

1
2
3
event:

		

show code

var $demo = $('#demo-touchevents');
var $event = $demo.find('.event span');
var $detail = $demo.find('.detail');
var flipsnap = Flipsnap('#demo-touchevents .flipsnap', {
    distance: 230
});
flipsnap.element.addEventListener('fstouchstart', function(ev) {
    $event.text('fstouchstart');
}, false);

flipsnap.element.addEventListener('fstouchmove', function(ev) {
    $event.text('fstouchmove');
    $detail.text(JSON.stringify({
        delta: ev.delta,
        direction: ev.direction
    }, null, 2));
}, false);

flipsnap.element.addEventListener('fstouchend', function(ev) {
    $event.text('fstouchend');
    $detail.text(JSON.stringify({
        moved: ev.moved,
        originalPoint: ev.originalPoint,
        newPoint: ev.newPoint,
        cancelled: ev.cancelled
    }, null, 2));
}, false);

cancel move (only next)

1
2
3
event:

		

show code

flipsnap.element.addEventListener('fstouchmove', function(ev) {
    // if touchmove to prev, when touchmove event cancel
    if (ev.direction === -1) {
        ev.preventDefault();
        flipsnap.moveToPoint(ev.newPoint);
    }
});
Fork me on GitHub