let initialYOffset = window.pageYOffset;
let parallaxContainers = document.querySelectorAll('.parallax');
window.addEventListener('scroll', function (event) {
if (window.pageYOffset > initialYOffset) { // При скролле вниз
parallaxContainers.forEach(function (item) {
let currentBackgroundPos = item.style.backgroundPositionY;
if (currentBackgroundPos) {
if (parseInt(currentBackgroundPos) > -50) {
item.style.backgroundPositionY = (parseInt(currentBackgroundPos) - 2) + 'px';
}
} else {
item.style.backgroundPositionY = '0px';
}
});
} else { // При скролле вверх
parallaxContainers.forEach(function (item) {
let currentBackgroundPos = item.style.backgroundPositionY;
if (parseInt(currentBackgroundPos) != 0) {
item.style.backgroundPositionY = (parseInt(currentBackgroundPos) + 2) + 'px';
}
});
}
initialYOffset = window.pageYOffset;
});
<script>
let sum = document.querySelector('#sum');
sum.addEventListener('click', function(){
// открытие и закрытие
if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen();
document.webkitCancelFullScreen();
} else {
document.documentElement.mozRequestFullScreen();
document.mozCancelFullScreen();
}
});
</script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="sum"><img width="20" height="20" src="Без названия.png" alt=""></button>
<script>
let sum = document.querySelector('#sum');
sum.addEventListener('click', function(){
// открытие
if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen();
} else {
document.documentElement.mozRequestFullScreen();
}
// закрытие
if (document.documentElement.webkitRequestFullscreen) {
document.webkitCancelFullScreen();
} else {
document.mozCancelFullScreen();
}
});
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="sum"><img width="20" height="20" src="Без названия.png" alt=""></button>
<script>
let sum = document.querySelector('#sum');
sum.addEventListener('click', function(){
if (document.fullscreenElement) {
if (document.documentElement.webkitRequestFullscreen) {
document.webkitCancelFullScreen();
}
else {
document.mozCancelFullScreen();
}
}
else {
if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen();
}
else {
document.documentElement.mozRequestFullScreen();
}
}
});
</script>
</body>
</html>