1

我目前正在尝试通过复制以下内容来使用 stellar.js 查询插件实现视差背景:http: //markdalgleish.com/projects/stellar.js/demos/backgrounds.html

当调用 stellar 函数时,似乎没有任何变化。

这是我的尝试,对我哪里出错有任何想法吗?
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
    });
});
4

1 回答 1

2

我重新添加了 stellar.js 文件,它工作正常。我认为您的问题是所有视差速度都设置为相同,因此很难区分。我在这个小提琴中改变了一些速度,你可以分辨出来 -

http://jsfiddle.net/4eBDE/72/

<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>
于 2013-12-04T16:52:52.493 回答