Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SmithDaria
Copy link
Contributor

@SmithDaria SmithDaria commented Jan 20, 2025

@keksobot keksobot changed the title Сделала домашку 9.2 Помощь друга Jan 20, 2025
Comment on lines 236 to +238
<script type="module" src="./js/main.js"></script>
<script src="./vendor/pristine/pristine.min.js"></script>
<script src="./vendor/nouislider/nouislider.js"></script>

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>

Тут нужно поправить порядок подключения скриптов. Сначала правильнее подключать библиотеки, а после уже свои скрипты

Comment on lines +17 to +94
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})`;
});
}
}

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 и применять уже к нему обвязку

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants