您的位置:首页 > Web前端 > JavaScript

WOW.js – 让页面滚动更有趣

2016-01-13 10:45 621 查看
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>WOW.js演示_dowebok</title>
<link rel="stylesheet" href="http://cdn.dowebok.com/98/css/animate.min.css">
<style>
* { margin: 0; padding: 0;}
body { overflow-x: hidden; font-family: "Microsoft Yahei";}
body h1 { width: 100%; margin: 80px 0; font-size: 50px; font-weight: 500; text-align: center;}
body .txt { margin: 80px 0; font-size: 16px; text-align: center;}
.dowebok { margin: 0 auto;}
.dowebok ul { list-style-type: none;}
.dowebok .row { font-size: 0; text-align: center;}
.dowebok .wow { display: inline-block; width: 280px; height: 280px; margin: 30px 15px 0; border-radius: 50%; font: 30px/280px "Microsoft Yahei"; vertical-align: top; *display: inline; zoom: 1;}
.bg-green { background: #5bd5a0;}
.bg-blue { background: #1daee9;}
.bg-purple { background: #c843a5;}
.bg-red { background: #eb3980;}
.bg-yellow { background: #ffcc35;}
</style>
</head>

<body>
<h1>WOW.js - 让页面滚动更有趣</h1>

<p class="txt">WOW.js 能让页面滚动时显示动画,使页面更有趣。</p>

<div class="dowebok">
<div class="row">
<div class="wow rollIn bg-blue"></div>
<div class="wow bounceInDown bg-green">WOW.js</div>
<div class="wow lightSpeedIn bg-purp
d11e
le"></div>
</div>

<div class="row">
<div class="wow rollIn bg-yellow" data-wow-delay="0.5s">简单易用</div>
<div class="wow pulse bg-red" data-wow-iteration="5" data-wow-duration="0.15s"></div>
<div class="wow bounceInRight bg-blue">轻量级</div>
</div>

<div class="row">
<div class="wow bounceInLeft bg-green"></div>
<div class="wow flipInX bg-purple">WOW.js</div>
<div class="wow bounceInRight bg-yellow"></div>
</div>

<div class="row">
<div class="wow rollIn bg-blue">无需 jQuery</div>
<div class="wow shake bg-red" data-wow-iteration="5" data-wow-duration="0.15s"></div>
<div class="wow swing bg-purple" data-wow-iteration="2">纯 JS</div>
</div>

<div class="row">
<div class="wow rollIn bg-red"></div>
<div class="wow bounceInU bg-yellow" data-wow-delay="0.5s">WOW.js</div>
<div class="wow lightSpeedIn bg-green" data-wow-delay="0.5s" data-wow-duration="0.15s"></div>
</div>

<div class="row">
<div class="wow bounceInLeft bg-purple">依赖 animate.css</div>
<div class="wow pulse bg-blue" data-wow-iteration="5" data-wow-duration="0.25s"></div>
<div class="wow lightSpeedIn bg-yellow">多种动画</div>
</div>

<div class="row">
<div class="wow bounce bg-green" data-wow-iteration="5" data-wow-duration="0.15s"></div>
<div class="wow bounceInUp bg-red">WOW.js</div>
<div class="wow bounceInRight bg-purple"></div>
</div>

<div class="row">
<div class="wow rollIn bg-red" data-wow-delay="0.5s">无需 jQuery!?</div>
<div class="wow bounceInDown bg-green" data-wow-delay="1s"></div>
<div class="wow bounceInRight bg-yellow" data-wow-delay="1.5s">谢谢</div>
</div>
</div>

<script src="http://cdn.dowebok.com/131/js/wow.min.js"></script>
<script>
if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))){
new WOW().init();
};
</script>
</body>
</html>


有的页面在向下滚动的时候,有些元素会产生细小的动画效果。虽然动画比较小,但却能吸引你的注意。比如刚刚发布的 iPhone 6 的页面(查看)。如果你希望你的页面也更加有趣,那么你可以试试 WOW.js。

WOW.js 依赖 animate.css,所以它支持 animate.css 多达 60 多种的动画效果,能满足您的各种需求。

浏览器兼容

IE6、IE7 等老旧浏览器不支持 CSS3 动画,所以没有效果;而 wow.js 也使用了 querySelectorAll 方法,IE 低版本会报错。为了达到更好的兼容,最好加一个浏览器及版本判断。

使用方法

1、引入文件

<link rel="stylesheet" href="css/animate.min.css">


2、HTML

<div class="wow slideInLeft"></div>
<div class="wow slideInRight"></div>


可以加入 data-wow-duration(动画持续时间)和 data-wow-delay(动画延迟时间)属性,如:

<div class="wow slideInLeft" data-wow-duration="2s" data-wow-delay="5s"></div>
<div class="wow slideInRight" data-wow-offset="10"  data-wow-iteration="10"></div>


3、JavaScript

new WOW().init();


如果需要自定义配置,可如下使用:

var wow = new WOW({
boxClass: 'wow',
animateClass: 'animated',
offset: 0,
mobile: true,
live: true
});
wow.init();


配置

属性/方法类型默认值说明
boxClass字符串‘wow’需要执行动画的元素的 class
animateClass字符串‘animated’animation.css 动画的 class
offset整数0距离可视区域多少开始执行动画
mobile布尔值true是否在移动设备上执行动画
live布尔值true异步加载的内容是否有效
参考:http://www.dowebok.com/131.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: