Skip to content

Instantly share code, notes, and snippets.

@itchief

itchief/script.js

Last active Jul 24, 2018
Embed
What would you like to do?
js-amsterdam
$('.circle-slider').find('.slider-arrow.next').on('click', function () {
$this = $(this).closest('.circle-slider');
var index = parseInt($this.attr('data-state')) + 1;
if (index <= $this.find('.item').length) {
$this.attr('data-state', index);
} else {
$this.attr('data-state', 1);
}
});
$('.circle-slider').find('.slider-arrow.prev').on('click', function () {
$this = $(this).closest('.circle-slider');
var index = parseInt($this.attr('data-state')) - 1;
if (index < 1) {
$this.attr('data-state', $this.find('.item').length);
} else {
$this.attr('data-state', index);
}
});
// код который правим
var
pageY = 0,
porog = 20;
$('.circle-slider').on('mousedown', '.item', function (e) {
pageY = e.pageY;
var that = e.delegateTarget;
var $this = $(that);
$(that).on('mousemove', function (e) {
if (e.pageY > pageY + porog) {
pageY = e.pageY;
var index = parseInt($this.attr('data-state')) + 1;
if (index <= $this.find('.item').length) {
$this.attr('data-state', index);
} else {
$this.attr('data-state', 1);
}
$(that).off('mousemove');
} else if (e.pageY < pageY - porog) {
pageY = e.pageY;
var index = parseInt($this.attr('data-state')) - 1;
if (index < 1) {
$this.attr('data-state', $this.find('.item').length);
} else {
$this.attr('data-state', index);
}
$(that).off('mousemove');
}
});
});
$('.circle-slider').on('mouseup mouseleave', function (e) {
$(this).off('mousemove');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment