2016-11-16 120 views
1

在阅读THIS教程并使用他们的代码后,我试图使用scrollReveal.js,但是当我的视口位于它们上面时,我仍然无法让我的div淡入。滚动显示不能正常工作

的Html

<head> 
<script src="scrollreveal-master/dist/scrollreveal.min.js"></script> 
</head> 

<div data-sr>This is the first div</div> 
<div data-sr>This is the second div</div> 
<div data-sr>This is yet another div</div> 

的JavaScript

new scrollReveal(); 

当我在我的网页上查看控制台,它说

未捕获的ReferenceError:scrollReveal没有定义

+0

,能得到任何其他错误,如一个404错误?你的代码在哪里? *在您加载'scrollreveal.min.js'之后它来了吗?此外,该网站似乎有一个错字。它应该是'新的ScrollReveal()' –

+0

我只收到一个错误(“参考错误”)。而我的代码是在我的身体标记的末尾,我在我的头部开始加载scrollReveal。 –

+0

@RhysEdwards尝试在页面末尾的脚本之前加载库 – Alexis

回答

3

尝试这样使用scrollReveal

<!DOCTYPE html> 
<html> 

    <head> 
    <meta charset="utf-8" /> 
    <title></title> 
    <link rel="stylesheet" href="style.css" /> 


</head> 

<body> 

<div id="main"> 

<div data-sr> one </div> 
<div data-sr> two </div> 
<div data-sr> three </div> 

</div> 

<script src="https://unpkg.com/[email protected]/dist/scrollreveal.min.js"></script> 

<script> 

// Changing the defaults 
window.sr = ScrollReveal({ reset: true }); 

// Customizing a reveal set 
sr.reveal('div', {opacity: 0.9,duration:3000}); 

</script> 

</body> 

</html> 

工作实例上滚动添加动画:https://plnkr.co/edit/qC33zle0fafyAL0RjkVl?p=preview