Last active
July 24, 2018 14:36
-
-
Save itchief/17313b6c215bf0328b43fcf6b5911b10 to your computer and use it in GitHub Desktop.
js-amsterdam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.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