-
Notifications
You must be signed in to change notification settings - Fork 0
add 0 Task + carousel, confused in numbers and called a branch of hom… #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
0cdbe4e
b0ee022
7b8e597
493655f
b2afbfb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>HomeWork 17 Part 2</title> | ||
| </head> | ||
| <body> | ||
| <div class="fetch"></div> | ||
| <script src="src/top-style.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,9 +45,31 @@ class Carousel { | |
| this.transition = element.transition, | ||
| this.infinity = element.infinity, | ||
| this.nav = element.nav, | ||
| this.timer = element.timer | ||
| this.timer = element.timer, | ||
| this.list = carousel.querySelectorAll('li'); | ||
| } | ||
| start() { | ||
| static initialize(properties) { | ||
| let myInitializedCarousel = new Carousel(properties); | ||
| myInitializedCarousel.start(); | ||
| } | ||
| infinityCarousel () { | ||
| let last = this.list.length - 1; | ||
| if (!this.list[last].classList.contains('active')) { | ||
| for (let i = 0; i < this.list.length; i ++) { | ||
| let nextPosition = parseInt(this.list[i].style.left) - this.widthImg * this.count; | ||
| this.list[i].style.left = nextPosition + 'px'; | ||
| let position = parseInt(this.list[i].style.left); | ||
| if (position === 0) { | ||
| this.list[i].classList.add('active') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about method toggle ? do you remember any ?:) |
||
| } else { | ||
| this.list[i].classList.remove('active') | ||
| } | ||
| } | ||
| } else if (this.list[last].classList.contains('active') && this.infinity === true) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We can ask user for set default active element for example to avoid such construction or something else |
||
| this.startCarousel(); | ||
| } | ||
| } | ||
| startCarousel () { | ||
| /*Объявляем перменные */ | ||
| let carousel = document.querySelector(this.elementToApply); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that method VERY BIG, can we split some logic to other methods? |
||
| let prev = carousel.querySelector('.prev'); | ||
|
|
@@ -64,7 +86,7 @@ class Carousel { | |
| const div = document.createElement('div'); | ||
| div.setAttribute('class', 'navigation'); | ||
| const ul = document.createElement('ul'); | ||
| for (let i = 0; i < list.length; i++) { | ||
| for (let i = 0; i < this.list.length; i++) { | ||
| const li = document.createElement('li'); | ||
| li.setAttribute('class', 'nav'); | ||
| li.innerHTML = i + 1; | ||
|
|
@@ -73,14 +95,14 @@ class Carousel { | |
| div.appendChild(ul); | ||
| let navs = []; | ||
|
|
||
| /* Добавьте внизу цифры с текущим активным изображением.*/ | ||
|
|
||
| if (nav === true) { | ||
| carousel.appendChild(div); | ||
| navs = carousel.querySelectorAll('.nav'); | ||
| } | ||
|
|
||
| /* Один круг карусели */ | ||
| /* Не получилось разделить метод на несколько, потому что при событии onclick | ||
| не получаеться обращаться к глобальной переменной this.list и надо переопредлять переменную list в саом методе */ | ||
|
|
||
| const newRoundCarusel = () => { | ||
| for (let i = 0; i < list.length; i ++) { | ||
|
|
@@ -139,37 +161,20 @@ class Carousel { | |
| } | ||
| }; | ||
| }; | ||
|
|
||
| /*Запускаем карусель */ | ||
|
|
||
| newRoundCarusel(); | ||
|
|
||
| } | ||
| start () { | ||
| this.startCarousel(); | ||
|
|
||
| /*Запускаем таймер, если он есть*/ | ||
|
|
||
| if (this.timer !== 0) { | ||
| setInterval(() => { | ||
| let last = list.length - 1; | ||
| if (!list[last].classList.contains('active')) { | ||
| for (let i = 0; i < list.length; i ++) { | ||
| let nextPosition = parseInt(list[i].style.left) - widthImg * count; | ||
| list[i].style.left = nextPosition + 'px'; | ||
| let position = parseInt(list[i].style.left); | ||
| if (position === 0) { | ||
| list[i].classList.add('active') | ||
| } else { | ||
| list[i].classList.remove('active') | ||
| } | ||
| } | ||
| } else if (list[last].classList.contains('active') && infinity === true) { | ||
| newRoundCarusel(); | ||
| } | ||
| this.infinityCarousel() | ||
| }, this.timer); | ||
| } | ||
| } | ||
| static initialize(properties) { | ||
| var myInitializedCarousel = new Carousel(properties); | ||
| myInitializedCarousel.start(); | ||
|
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -183,36 +188,6 @@ Carousel.initialize({ | |
| }); | ||
|
|
||
|
|
||
| /* | ||
| * TASK 2 | ||
| * Сделайте класс, который будет иметь метод topStyle | ||
| * метод topStyle принимает объект с CSS стилями и добавляет в <head> | ||
| * новый элемент с данными стилями | ||
| * | ||
| * | ||
| * */ | ||
| // .topStyle('fetch', {backgroundColor:'blue'}) | ||
| /* | ||
| * | ||
| * <style>.fetch { | ||
| * background-color | ||
| * */ | ||
|
|
||
| /* Не получилось */ | ||
| // | ||
| // class Style { | ||
| // topStyle (className, yourStyle) { | ||
| // document.head.innerHTML = | ||
| // `<style> | ||
| // .${className} { | ||
| // ${yourStyle} | ||
| // } | ||
| // </style>` | ||
| // } | ||
| // } | ||
| // const newStyle = new Style(); | ||
| // newStyle.topStyle('fetch', {backgroundColor:'blue'}); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
|
|
||
| /* | ||
| * TASK 2 | ||
| * Сделайте класс, который будет иметь метод topStyle | ||
| * метод topStyle принимает объект с CSS стилями и добавляет в <head> | ||
| * новый элемент с данными стилями | ||
| * | ||
| * | ||
| * */ | ||
| // .topStyle('fetch', {backgroundColor:'blue'}) | ||
| /* | ||
| * | ||
| * <style>.fetch { | ||
| * background-color | ||
| * */ | ||
|
|
||
| /* Не получилось */ | ||
|
|
||
| class Style { | ||
| standartViewStyle (property) { | ||
| return property.replace(/([a-z])([A-Z])/, '$1-$2').toLowerCase(); | ||
| } | ||
| topStyle (className, yourStyle) { | ||
| const style = document.createElement('style'); | ||
| let properties = ''; | ||
| for (let key in yourStyle) { | ||
| properties += `${this.standartViewStyle(key)}: ${yourStyle[key]}; | ||
| `; | ||
| } | ||
| style.innerHTML = `.${className} { | ||
| ${properties} | ||
| }`; | ||
| document.head.appendChild(style); | ||
|
|
||
| } | ||
| } | ||
| const newStyle = new Style(); | ||
| newStyle.topStyle('fetch', {backgroundColor:'blue', width: '100px', height: '100px', marginLeft: '100px', marginTop: '100px'}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there a bunch of calculations, want to think about it optimization a bit