我已经尝试了十多次使用parallax.js jquery插件。但这是行不通的。我不明白发生了什么事。

插件网站:http://matthew.wagerfield.com/parallax/

我的演示工作站点:http://contact.themeshef.com/

有人可以帮我了解如何使用视差js吗?
提前致谢!

页面来源:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        #container {
            width: 100%;
            height: 500px;
        }
    </style>

</head>
<body>
    <div id="container">
        <div id="scene">
          <div class="layer" data-depth="0.00"><img src="layer1.png"></div>
          <div class="layer" data-depth="0.20"><img src="layer2.png"></div>
          <div class="layer" data-depth="0.40"><img src="layer3.png"></div>
          <div class="layer" data-depth="0.60"><img src="layer4.png"></div>
          <div class="layer" data-depth="0.80"><img src="layer5.png"></div>
          <div class="layer" data-depth="1.00"><img src="layer6.png"></div>
        </div>
    </div>


    <script src="jquery-3.2.1.min.js"></script>
    <script src="parallax.js"></script>
    <script>
      var scene = document.getElementById('scene');
      var parallax = new Parallax(scene);
    </script>
</body>
</html>

最佳答案

您正在使用库的非编译版本。您应该编译和使用,或者可以从here下载parallax.min.js文件的编译版本,也可以使用cdn

在此示例中,我正在使用CDN



<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/parallax/2.1.3/parallax.min.js"></script>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        #container {
            width: 100%;
            height: 500px;
        }
    </style>

</head>
<body>
    <div id="container">
        <div id="scene">
          <div class="layer" data-depth="0.00"><img src="layer1.png"></div>
          <div class="layer" data-depth="0.20"><img src="layer2.png"></div>
          <div class="layer" data-depth="0.40"><img src="layer3.png"></div>
          <div class="layer" data-depth="0.60"><img src="layer4.png"></div>
          <div class="layer" data-depth="0.80"><img src="layer5.png"></div>
          <div class="layer" data-depth="1.00"><img src="layer6.png"></div>
        </div>
    </div>


    <script src="jquery-3.2.1.min.js"></script>
    <script src="parallax.js"></script>
    <script>
      var scene = document.getElementById('scene');
      var parallax = new Parallax(scene);
    </script>
</body>
</html>

08-18 02:58