我正在学习视差效果,并尝试在背景中显示视频而不是图像。
因此,我使用了背景图片创建了一个很好的效果。
这是我的 jQuery 代码:
$('[data-parallax]').each(function(){
var $this = $(this),
$window = $(window);
$window.scroll(function() {
var y = -($window.scrollTop() / $this.data('speed')),
background = '50% '+ y + 'px';
$this.css('background-position', background);
});
});
我的CSS:
[data-parallax] {
background-attachment: fixed;
background-color: #fff;
background-image: url('http://lorempixel.com/720/480');
background-position: 50% 0;
background-repeat: no-repeat;
background-size: cover;
min-height: 100%;
position: relative;
}
示例: http://jsfiddle.net/7a2ky/show/
代码: http://jsfiddle.net/7a2ky/
我想用视频 (http://goo.gl/HcH2cL) 来实现相同的效果。这可行吗?
video
元素来“模拟”背景。但是没有成功。 - Caio Tarifa