に私は私の背景画像の2に視差効果を与えることに取り組んでいますし、それは最初の画像の上ではなく、二image..theコードに取り組んでいないが視差スクロール1枚の画像で作業しますが、他の
以下の通りですjqueryの:
$(document).ready(function() {
$('section[data-type="background"]').each(function() {
var $bgobj = $(this); // assigning the object
$(window).scroll(function() {
// scroll the background at var speed
// the yPos is a negative value because we're scrolling it UP!
var yPos = -($window.scrollTop()/$bgobj.data('speed'));
// Put together our final background position
var coords = '50% '+ yPos + 'px';
// Move the background
$bgobj.css({ backgroundPosition: coords });
}); // end window scroll
});
});
HTML: -
<section class="parallax" data-type="background" data-speed="5">
<h2>Check out this cool parallax scrolling effect. Use these ribbons to display calls to action mid-page.</h2>
<button class="btn btn-lg btn-info">PARALLAX</button>
</section>
CSS: -
.parallax {
height:35em;
background: url('https://images.unsplash.com/photo-1463123081488-789f998ac9c4?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=6d1a6d1c5a7eb63d0c411b1d019f0b30');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
}
.parallax h2 {
color: white;
text-align: center;
padding: 1em;
padding-top: 5em;
}
.parallax button {
display: block;
margin: 2em auto;
}
奇妙な部分は、第2の画像が全く表示されませんし、私は、データ速度の属性を削除したが、その後、視差がwork..Iが立ち往生して混乱していない場合にのみ..だから
ありがとうございました。もしあなたが気にしていないのであれば、あなたがしたことを教えてください。(jqueryは私にとって強いポイントではありません).. –
確かに、$ bgobj.offset documentに対する要素のx/y位置を持つオブジェクトをscrollTop()の値から引いて、イメージyPosが常に0から始まるようにします。 – phynam
説明をありがとう.. –