【发布时间】:2018-09-07 03:28:26
【问题描述】:
我在这个图片网站上工作时使用了视差效果,但我想知道它为什么会剪裁图片以及如何纠正上述问题。 每当我向下滚动一定长度时,它会切断图片并开始下一张,但随后会将另一张带回顶部。 当您到达底部图片时,它会显示顶部在底部和底部在顶部。
<section class="home">
<div class="pic img1 parallax"></div>
<div class="pic img2 parallax"></div>
<div class="pic img3 parallax"></div>
<div class="pic img4 parallax"></div>
</section>
body {
box-sizing: border-box;
margin: 0;
}
section {
width: 100%;
height: 50em;
}
.pic {
width: 100%;
height: 50em;
background-size: cover;
background-position: center;
}
.img1 {
background-image: url('https://images.unsplash.com/photo-1536164832230-6c238c58f740?ixlib=rb-0.3.5&s=09987436d4a89cf8c848c93aa574dfda&auto=format&fit=crop&w=1650&q=80');
}
.img2 {
background-image: url('https://images.unsplash.com/photo-1536221236547-04007cfc3d8b?ixlib=rb-0.3.5&s=426505fd76bd618fdd95640f8870e38c&auto=format&fit=crop&w=1650&q=80');
}
.img3 {
background-image: url('https://images.unsplash.com/photo-1536171010494-d89014448ca1?ixlib=rb-0.3.5&s=4f7b5d0b81a5f1e1445a86fd9a251a46&auto=format&fit=crop&w=1576&q=80');
}
.img4 {
background-image: url('https://images.unsplash.com/photo-1536108978996-128e3e2a9783?ixlib=rb-0.3.5&s=31ce21b0ec2bb391c601c681fc1c7952&auto=format&fit=crop&w=1475&q=80');
}
//jQuery Parallax
$(document).ready(function() {
$(window).scroll(function() {
parallax();
})
function parallax() {
var wScroll = $(window).scrollTop();
//select element, class, id etc and property
$('.pic').css('background-position', 'center ' +(wScroll)+'px')
//you can also change speed
}
});
【问题讨论】:
标签: jquery html css scroll parallax