我目前正在尝试使用stellar.js查询插件实现视差背景,方法是复制:http://markdalgleish.com/projects/stellar.js/demos/backgrounds.html
当调用恒星函数时似乎没有任何改变。
这是我的尝试,任何关于我哪里出错的想法?
http://jsfiddle.net/4eBDE/55/
HTML:
<body>
<h1><a href="../">Stellar.js</a> Backgrounds Demo</h1>
<div class="photo summer" data-stellar-background-ratio="0.5"><span>Summer</span></div>
<div class="photo autumn" data-stellar-background-ratio="0.5"><span>Autumn</span></div>
<div class="photo winter" data-stellar-background-ratio="0.5"><span>Winter</span></div>
<div class="photo spring" data-stellar-background-ratio="0.5"><span>Spring</span></div>
<div class="photo summer" data-stellar-background-ratio="0.5"><span>Summer</span></div>
<div class="photo autumn" data-stellar-background-ratio="0.5"><span>Autumn</span></div>
<div class="photo winter" data-stellar-background-ratio="0.5"><span>Winter</span></div>
<div class="photo spring" data-stellar-background-ratio="0.5"><span>Spring</span></div>
</body
CSS:
* {
margin: 0;
padding: 0;
}
body {
font-family: helvetica, arial;
padding-top: 40px;
}
h1 {
background-color: black;
color: white;
height: 40px;
font-size: 24px;
font-weight: normal;
left: 0;
line-height: 40px;
position: fixed;
text-align: center;
top: 0;
width: 100%;
z-index: 1;
}
h1 a {
border-bottom: 1px solid white;
color: white;
display: inline-block;
line-height: 30px;
text-decoration: none;
}
.photo {
background-attachment: fixed;
background-position: 50% 0;
background-repeat: no-repeat;
height: 450px;
position: relative;
}
.photo span {
bottom: 0;
color: white;
display: block;
left: 50%;
margin-left: -640px;
font-size: 38px;
padding: 10px;
position: absolute;
text-shadow: 0 2px 0 black, 0 0 10px black;
width: 1280px;
}
.summer {
background-image: url(http://markdalgleish.com/projects/stellar.js/demos/images/summer.jpg);
}
.autumn {
background-image: url(http://markdalgleish.com/projects/stellar.js/demos/images/autumn.jpg);
}
.winter {
background-image: url(http://markdalgleish.com/projects/stellar.js/demos/images/winter.jpg);
}
.spring {
background-image: url(http://markdalgleish.com/projects/stellar.js/demos/images/spring.jpg);
}
使用Javascript:
$(function () {
$.stellar({
horizontalScrolling: false,
verticalOffset: 40
});
});
答案 0 :(得分:2)
我重新添加了stellar.js文件,它可以正常工作。我认为你的问题是所有的视差速度设置相同,所以很难区分。我改变了这个小提琴中的一些速度,你可以分辨出来 -
<div class="photo summer" data-stellar-background-ratio="2"><span>Summer</span></div>
<div class="photo autumn" data-stellar-background-ratio="0.5"><span>Autumn</span></div>