-
Notifications
You must be signed in to change notification settings - Fork 1
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
Помощь друга #10
base: master
Are you sure you want to change the base?
Помощь друга #10
Conversation
<script type="module" src="./js/main.js"></script> | ||
<script src="./vendor/pristine/pristine.min.js"></script> | ||
<script src="./vendor/nouislider/nouislider.js"></script> |
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.
<script src="./vendor/pristine/pristine.min.js"></script>
<script src="./vendor/nouislider/nouislider.js"></script>
<script type="module" src="./js/main.js"></script>
Тут нужно поправить порядок подключения скриптов. Сначала правильнее подключать библиотеки, а после уже свои скрипты
sliderEffect.noUiSlider.on('update', () => { | ||
valueEffect.value = sliderEffect.noUiSlider.get(); | ||
}); | ||
effectLevel.classList.add('hidden'); | ||
|
||
function onEffectListChange (evt) { | ||
const effect = evt.target.value; | ||
if (effect === 'none') { | ||
effectLevel.classList.add('hidden'); | ||
previewPhoto.removeAttribute('style'); | ||
} else if (effect === 'chrome') { | ||
effectLevel.classList.remove('hidden'); | ||
sliderEffect.noUiSlider.updateOptions({ | ||
range: { | ||
min: 0, | ||
max: 1, | ||
}, | ||
start: 1, | ||
step: 0.1, | ||
}); | ||
valueEffect.value = sliderEffect.noUiSlider.get(); | ||
sliderEffect.noUiSlider.on('update', () => { | ||
previewPhoto.style.filter = `grayscale(${valueEffect.value})`; | ||
}); | ||
} else if (effect === 'sepia') { | ||
effectLevel.classList.remove('hidden'); | ||
sliderEffect.noUiSlider.updateOptions({ | ||
range: { | ||
min: 0, | ||
max: 1, | ||
}, | ||
start: 1, | ||
step: 0.1, | ||
}); | ||
sliderEffect.noUiSlider.on('update', () => { | ||
previewPhoto.style.filter = `sepia(${valueEffect.value})`; | ||
}); | ||
} else if (effect === 'marvin') { | ||
effectLevel.classList.remove('hidden'); | ||
sliderEffect.noUiSlider.updateOptions({ | ||
range: { | ||
min: 0, | ||
max: 100, | ||
}, | ||
start: 100, | ||
step: 1, | ||
}); | ||
sliderEffect.noUiSlider.on('update', () => { | ||
previewPhoto.style.filter = `invert(${valueEffect.value}%)`; | ||
}); | ||
} else if (effect === 'phobos') { | ||
effectLevel.classList.remove('hidden'); | ||
sliderEffect.noUiSlider.updateOptions({ | ||
range: { | ||
min: 0, | ||
max: 3, | ||
}, | ||
start: 3, | ||
step: 0.1, | ||
}); | ||
sliderEffect.noUiSlider.on('update', () => { | ||
previewPhoto.style.filter = `blur(${valueEffect.value}px)`; | ||
}); | ||
} else if (effect === 'heat') { | ||
effectLevel.classList.remove('hidden'); | ||
sliderEffect.noUiSlider.updateOptions({ | ||
range: { | ||
min: 1, | ||
max: 3, | ||
}, | ||
start: 3, | ||
step: 0.1, | ||
}); | ||
sliderEffect.noUiSlider.on('update', () => { | ||
previewPhoto.style.filter = `brightness(${valueEffect.value})`; | ||
}); | ||
} | ||
} |
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.
Модуль с фильтрами можно значительно улучшить. Такие задачки обычно решаются с описанием конфигурации фильтров.
Наподобии такого, можно заиспользовать у себя
const EFFECT_SETTINGS = {
none: {
hidden: true,
filter: null,
},
chrome: {
range: { min: 0, max: 1 },
start: 1,
step: 0.1,
filter: (value) => `grayscale(${value})`
},
sepia: {
range: { min: 0, max: 1 },
start: 1,
step: 0.1,
filter: (value) => `sepia(${value})`
},
marvin: {
range: { min: 0, max: 100 },
start: 100,
step: 1,
filter: (value) => `invert(${value}%)`
},
phobos: {
range: { min: 0, max: 3 },
start: 3,
step: 0.1,
filter: (value) => `blur(${value}px)`
},
heat: {
range: { min: 1, max: 3 },
start: 3,
step: 0.1,
filter: (value) => `brightness(${value})`
}
};
Такую структуру очень легко расширять.
Из объекта можно считывать выбранный фильтров const effect = evt.target.value; дабы избежать if-else и применять уже к нему обвязку
🎓 Помощь друга