使用Html5实现树叶飘落的效果


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

const NUMBER_OF_LEAVES = 30;

function init(){

    var container = document.getElementById('leafContainer');

    for (var i = 0; i < NUMBER_OF_LEAVES; i++) {

        container.appendChild(createALeaf());

    }

}

 

function randomInteger(low, high){

    return low + Math.floor(Math.random() * (high - low));

}

 

function randomFloat(low, high){

    return low + Math.random() * (high - low);

}

 

function pixelValue(value){

    return value + 'px';

}

 

function durationValue(value){

    return value + 's';

}

 

function createALeaf(){

    var leafDiv = document.createElement('div');

    leafDiv.style.top = "-100px";

    leafDiv.style.left = pixelValue(randomInteger(0, 500));

    leafDiv.style.webkitAnimationName = 'fade, drop';

    var fadeAndDropDuration = durationValue(randomFloat(5, 11));

    leafDiv.style.webkitAnimationDuration = fadeAndDropDuration + ', ' + fadeAndDropDuration;

    var leafDelay = durationValue(randomFloat(0, 5));

    leafDiv.style.webkitAnimationDelay = leafDelay + ', ' + leafDelay;

     

    var image = document.createElement('img');

    image.src = 'images/realLeaf' + randomInteger(1, 5) + '.png';

    var spinAnimationName = (Math.random() < 0.5) ? 'clockwiseSpin' : 'counterclockwiseSpinAndFlip';

    image.style.webkitAnimationName = spinAnimationName;

    var spinDuration = durationValue(randomFloat(4, 8));

    image.style.webkitAnimationDuration = spinDuration;

 

    leafDiv.appendChild(image);

    return leafDiv;

}

 

window.addEventListener('load', init, false);

以上就是使用Html5实现树叶飘落的效果的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

animation-delay属性怎么用

利用HTML5的一个特性- deviceorientation来实现手机上摇一摇功能

什么是h5页面

HTML5需遵循怎样的6个设计原则?

浅谈关于HTML5头部<meta>标签的小知识

HTML5是什么?HTML5有什么用?

HTML5 source type有什么用处?HTML5 source标签的详细介绍

HTML5实战-svg的详解

h5是什么

通过案例,了解css3创建简单动画的方法

更多相关阅读请进入《HTML5》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...