Skip to content

Instantly share code, notes, and snippets.

@itchief
Last active July 24, 2018 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itchief/17313b6c215bf0328b43fcf6b5911b10 to your computer and use it in GitHub Desktop.
Save itchief/17313b6c215bf0328b43fcf6b5911b10 to your computer and use it in GitHub Desktop.
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