Skip to content

Commit

Permalink
Merge pull request #5 from guimontme/1205-slide-config
Browse files Browse the repository at this point in the history
Configurando os Indexes do slide
  • Loading branch information
guimontme authored Aug 11, 2021
2 parents faffede + b943881 commit 5b06969
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion public/js/script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ import Slide from './slide';

const slide = new Slide('.slide', '.slide-wrapper');
slide.init();
slide.changeSlide(2);
32 changes: 31 additions & 1 deletion src/js/slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class Slide {
}

updatePosition(clientX) {
this.dist.movement = (this.dist.startX - clientX) * 1.8;
this.dist.movement = (this.dist.startX - clientX) * 1.6;
return this.dist.finalPosition - this.dist.movement;
}

Expand Down Expand Up @@ -54,9 +54,39 @@ export default class Slide {
this.onEnd = this.onEnd.bind(this);
}

/* Slides Config */
slidePosition(slide) {
const margin = (this.wrapper.offsetWidth - slide.offsetWidth) / 2;
return -(slide.offsetLeft - margin);
}
slideConfig() {
this.slideArray = [...this.slide.children].map((element, index) => {
const position = this.slidePosition(element)
return { position, element }
});
return this.slideArray;
}

slideIndexNav(index) {
const last = this.slideArray.length - 1;
this.index = {
prev: index ? index - 1 : last,
active: index,
next: index === last ? 0 : index + 1,
}
}

changeSlide(index) {
const activeSlide = this.slideArray[index];
this.dist.finalPosition = activeSlide.position;
this.moveSlide(activeSlide.position);
this.slideIndexNav(index);
}

init() {
this.bindEvents();
this.addSlideEvents();
this.slideConfig();
return this;
}
}
1 change: 1 addition & 0 deletions src/sass/_slide.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
max-width: 800px;
margin: 0 20px;
}
// transform: translate3d(-1259px, 0px, 0px);
}
}

0 comments on commit 5b06969

Please sign in to comment.