我的.js文件无法链接到我的HTML,无法使scrollmagic正常工作

时间:2019-04-17 22:23:57

标签: javascript jquery html css scrollmagic

我正在尝试在网页上使用ScrollMagic。我已经在.js文件中输入了代码,并且已将此文件和ScrollMagic cdn都链接到了我的html,但是对我的页面没有任何影响。

我尝试将../添加到文件链接并添加不同的脚本

这是HTML:

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://fonts.googleapis.com/css?family=Sarabun" 
rel="stylesheet">
<link rel="stylesheet" href="css/styles2.css">
<title>Example</title>
</head>

<body>
<header>
<h1>Header section</h1>
</header>
<section class="about">
<div class="about-title">
  <h2>About Us</h2>
</div>
<div class="about-pages">
  <div>
    <h2>Project 1</h2>
    <p>Lorem ipsum dolor sit amet, </p>
  </div>
  <div>
    <h2>Project 1</h2>
    <p>Lorem ipsum dolor sit amet, </p>
  </div>
  <div>
    <h2>Project 1</h2>
    <p>Lorem ipsum dolor sit amet</p>
  </div>
  </div>
  </section>


<footer>
<h2> This is the footer </h2>
</footer>

<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.6/ScrollMagic.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.6/plugins/debug.addIndicators.min.js"></script>
<script src="app.js"></script>

</body>

这是app.js代码:

function splitScroll(){
const controller = new ScrollMagic.Controller();
new ScrollMagic.Scene({
duration: '200%',
triggerElement: '.about-title'
triggerHook: 0; 
})

.setPin('.about-title');
.addIndicators();
.addTo(controller);
 }

splitScroll();

我希望页面的左侧保持静止不动,而右侧则滚动,但是全部一次滚动。

1 个答案:

答案 0 :(得分:1)

我在您的JS代码中看到了一些错误。对象属性应以逗号结尾。您缺少一个。您也不应在最后一个冒号后加上分号。

new ScrollMagic.Scene({
duration: '200%',
triggerElement: '.about-title',
triggerHook: 0 
})

另一个问题是您有不必要的分号导致了链接问题...

.setPin('.about-title')
.addIndicators()
.addTo(controller); // This one may need to be removed also

最后,我看到触发器已附加到类(.about-title)上。我在您的html中看不到该类。