console
window.onscroll = function(e) {
let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
let img2_offsetTop = document.getElementsByClassName('img')[0].offsetTop;
if(scrollTop > 82 && scrollTop < 482) {
console.log('scrollTop: ' + scrollTop)
changeImg(1, scrollTop - 82)
}
}
function changeImg(index, width) {
let img = document.getElementById('img' + index);
img.style.width = width + 'px'
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>滚动效果</title>
</head>
<body>
<div class="box">
<div class="img">
<img src="http://static.runoob.com/images/demo/demo1.jpg" alt="" id="img1">
<img src="http://static.runoob.com/images/demo/demo2.jpg" alt="" id='img2'>
</div>
</div>
</body>
</html>
.box {
position: relative;
height: 180vh;
}
img {
width: 100%;
}
.img {
bottom: 100vh;
position: absolute;
width: 100%;
}
#img1 {
position: absolute;
width: 50%;
z-index: 100;
border-radius: 50%;
}
#img2 {
position: absolute;
width: 100%;
}