Задать вопрос
Fox7777
@Fox7777
Люблю python

Как остановить скролл на последнем фрейме?

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="stylesheet" href="style.css">
	<title>Квартира</title>
</head>

<body>
	<div class="container">
		<section class="gallery">
			<div class="frame frame-bg">
				<div class="frame-content">
					<h2>minimalism</h2>
				</div>
			</div>
			<div class="frame">
				<div class="frame-content">
					<div class="frame-media frame-media-left" style="background-image: url(img/1.jpg);"></div>
				</div>
			</div>
			<div class="frame">
				<div class="frame-content text-right">
					<h3>comfortable</h3>
					<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsa optio illo accusamus excepturi, provident
						cupiditate omnis similique obcaecati tempore, amet explicabo sapiente animi ut itaque tempora rem minima
						laboriosam consequuntur!</p>
				</div>
			</div>
			<div class="frame">
				<div class="frame-content">
					<div class="frame-media frame-media-right" style="background-image: url(img/2.jpg);"></div>
				</div>
			</div>
			<div class="frame frame-bg">
				<div class="frame-content">
					<div class="frame-media frame-media-left" style="background-image: url(img/3.jpg);"></div>
				</div>
			</div>
			<div class="frame">
				<div class="frame-content">
					<div class="frame-media frame-media-right" style="background-image: url(img/4.jpg);"></div>
				</div>
			</div>
			<div class="frame frame-bg">
				<div class="frame-content frame-bg">
					<div class="frame-media frame-media-left" style="background-image: url(img/5.jpg);"></div>
				</div>
			</div>
			<div class="frame">
				<div class="frame-content">
					<h5>&copy; Almaz Gayazov</hr>
				</div>
			</div>
		</section>
	</div>
	<audio class="audio" src="media/ambient.mp3"></audio>
	<img class="soundbutton paused" src="./img/sound.gif" alt="" class="sound">
	<script src="main.js"></script>
</body>

</html>

let zSpacing = -1000,
	lastPos = zSpacing / 5,
	$frames = document.getElementsByClassName('frame'),
	frames = Array.from($frames),
	zVals = []

window.onscroll = function () {
	let top = document.documentElement.scrollTop,
		delta = lastPos - top
	lastPos = top

	frames.forEach(function (n, i) {
		zVals.push((i * zSpacing) + zSpacing)
		zVals[i] += delta * -5.5
		let frame = frames[i],
			transform = `translateZ(${zVals[i]}px)`,
		opacity = zVals[i] < Math.abs(zSpacing) / 1.8 ? 1 : 0
		
		frame.setAttribute('style', `transform: ${transform}; opacity: ${opacity}`)
	});
}
window.scrollTo(0, 1)


let soundbutton = document.querySelector('.soundbutton'),
		audio = document.querySelector('.audio')

soundbutton.addEventListener('click', e =>{
	soundbutton.classList.toggle('paused')
	audio.paused ? audio.play() : audio.pause()
})

window.onfocus = function(){
	soundbutton.classList.contains('paused') ? audio.pause() : audio.play()
}

window.onblur = function() {
	audio.pause()
}

Как сделать остановку скролла на последнем фрейме, никак не могу понять
  • Вопрос задан
  • 47 просмотров
Подписаться 1 Средний Комментировать
Решения вопроса 1
Lapita12
@Lapita12
Тесты, тесты?
let zSpacing = -1000,
  lastPos = zSpacing / 5,
  $frames = document.getElementsByClassName('frame'),
  frames = Array.from($frames),
  zVals = [];

const lastFrame = $frames[$frames.length - 1];
const lastFrameHeight = lastFrame.offsetHeight;
const lastFrameTop = lastFrame.offsetTop;

window.onscroll = function() {
  let top = document.documentElement.scrollTop,
    delta = lastPos - top
  lastPos = top

  frames.forEach(function(n, i) {
    zVals.push((i * zSpacing) + zSpacing)
    zVals[i] += delta * -5.5
    let frame = frames[i],
      transform = `translateZ(${zVals[i]}px)`,
    opacity = zVals[i] < Math.abs(zSpacing) / 1.8 ? 1 : 0
    
    frame.setAttribute('style', `transform: ${transform}; opacity: ${opacity};`);
  });

  if (top + window.innerHeight >= lastFrameTop + lastFrameHeight) {
    window.scrollTo(0, lastFrameTop);
  }
};

window.scrollTo(0, 1);

let soundbutton = document.querySelector('.soundbutton'),
    audio = document.querySelector('.audio')

soundbutton.addEventListener('click', e =>{
  soundbutton.classList.toggle('paused')
  audio.paused ? audio.play() : audio.pause()
})

window.onfocus = function(){
  soundbutton.classList.contains('paused') ? audio.pause() : audio.play()
}

window.onblur = function() {
  audio.pause()
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы
23 дек. 2024, в 11:07
10000 руб./за проект
23 дек. 2024, в 10:43
5000 руб./за проект
23 дек. 2024, в 10:32
2000 руб./за проект