Skip to content

Commit

Permalink
[BUGFIX] #16 Rebuild order when disabling ScrollSnapLoop Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
barthy committed May 6, 2022
1 parent 911b741 commit db67b9c
Show file tree
Hide file tree
Showing 22 changed files with 18 additions and 23 deletions.
Empty file modified .eslintrc.json
100644 → 100755
Empty file.
Empty file modified .github/FUNDING.yml
100644 → 100755
Empty file.
Empty file modified .github/workflows/npm-publish.yml
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .stylelintrc.json
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified bin/io.sh
100644 → 100755
Empty file.
Empty file modified demo/feature_toggle.css
100644 → 100755
Empty file.
Empty file modified demo/index.css
100644 → 100755
Empty file.
18 changes: 6 additions & 12 deletions demo/index.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,10 @@ const sliderElement = document.querySelector('.example-slider')
const slides = sliderElement.getElementsByClassName('scroll-snap-slide')
const slider = new ScrollSnapSlider(sliderElement)

slider.roundingMethod = function (x) {
const direction = x <= slider.slide ? -1 : 1

if (direction < 0) {
return Math.floor(x)
}

return Math.ceil(x)
}

/**
* @param {Number} x the current slide position as a decimal (e.g. 1,5 = slide at index 1 has been slided by 50%)
*/
slider.roundingMethod = function (x) {
// TODO return an integer that will be the the slider.slide
return Math.round(x)
}

Expand All @@ -46,7 +35,10 @@ for (const button of buttons) {
button.addEventListener('click', function (event) {
event.preventDefault()

const slideElementIndex = Array.from(slides).findIndex(item => item.dataset.index === button.control.value)
const slideElementIndex = Array.prototype.slice
.call(slides)
.findIndex(item => item.dataset.index === button.control.value)

slider.slideTo(slideElementIndex)
})
}
Expand Down Expand Up @@ -108,3 +100,5 @@ draggableInput.addEventListener('change', function () {

disablePlugin(draggablePlugin)
})

window.slider = slider
Empty file modified demo/page.css
100644 → 100755
Empty file.
Empty file modified index.html
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion package.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scroll-snap-slider",
"version": "2.4.0",
"version": "2.4.1",
"description": "Mostly CSS slider with great performance.",
"keywords": [
"slider",
Expand Down
Empty file modified src/ScrollSnapAutoplay.js
100644 → 100755
Empty file.
Empty file modified src/ScrollSnapDraggable.js
100644 → 100755
Empty file.
8 changes: 7 additions & 1 deletion src/ScrollSnapLoop.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ScrollSnapLoop extends ScrollSnapPlugin {
enable (slider) {
this.slider = slider
this.element = this.slider.element
this.slides = this.slider.element.getElementsByClassName('scroll-snap-slide')
this.slides = this.element.getElementsByClassName('scroll-snap-slide')

this.slider.addEventListener('slide-stop', this.loopSlides)
this.loopSlides()
Expand All @@ -26,6 +26,12 @@ export class ScrollSnapLoop extends ScrollSnapPlugin {
disable () {
this.slider.removeEventListener('slide-stop', this.loopSlides)

const sortedSlides = Array.prototype.slice
.call(this.slides)
.sort((a, b) => parseInt(a.dataset.index, 10) - parseInt(b.dataset.index, 10))

Element.prototype.append.apply(this.element, sortedSlides)

this.slider = null
this.element = null
this.slides = null
Expand Down
Empty file modified src/ScrollSnapPlugin.js
100644 → 100755
Empty file.
Empty file modified src/ScrollSnapSlider.js
100644 → 100755
Empty file.
Empty file modified src/scroll-snap-slider.css
100644 → 100755
Empty file.
Empty file modified src/scroll-snap-slider.scss
100644 → 100755
Empty file.
13 changes: 4 additions & 9 deletions yarn.lock
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -513,15 +513,10 @@ camelcase@^5.3.1:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==

caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001219, caniuse-lite@^1.0.30001274:
version "1.0.30001280"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001280.tgz#066a506046ba4be34cde5f74a08db7a396718fb7"
integrity sha512-kFXwYvHe5rix25uwueBxC569o53J6TpnGu0BEEn+6Lhl2vsnAumRFWEBhDft1fwyo6m1r4i+RqA4+163FpeFcA==

caniuse-lite@^1.0.30001245:
version "1.0.30001279"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001279.tgz"
integrity sha512-VfEHpzHEXj6/CxggTwSFoZBBYGQfQv9Cf42KPlO79sWXCD1QNKWKsKzFeWL7QpZHJQYAvocqV6Rty1yJMkqWLQ==
caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001219, caniuse-lite@^1.0.30001245, caniuse-lite@^1.0.30001274:
version "1.0.30001338"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001338.tgz"
integrity sha512-1gLHWyfVoRDsHieO+CaeYe7jSo/MT7D7lhaXUiwwbuR5BwQxORs0f1tAwUSQr3YbxRXJvxHM/PA5FfPQRnsPeQ==

chalk@^2.0.0:
version "2.4.2"
Expand Down

0 comments on commit db67b9c

Please sign in to comment.