基本信息
源码名称:红包散落特效 js示例源码
源码大小:0.02M
文件格式:.zip
开发语言:js
更新时间:2018-08-04
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 5 元×
微信扫码支付:5 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
(function() {
/* Define the number of leaves to be used in the animation */
var NUMBER_OF_LEAVES = 80;
/*
Called when the "Falling Leaves" page is completely loaded.
*/
function init() {
/* Get a reference to the element that will contain the leaves */
var container = document.getElementById('petalbox');
/* Fill the empty container with new leaves */
try {
for (var i = 0;
i < NUMBER_OF_LEAVES;
i ) {
container.appendChild(createALeaf());
}
}
catch(e) {
}
}
/*
Receives the lowest and highest values of a range and
returns a random integer that falls within that range.
*/
function randomInteger(low, high) {
return low Math.floor(Math.random() * (high - low));
}
/*
Receives the lowest and highest values of a range and
returns a random float that falls within that range.
*/
function randomFloat(low, high) {
return low Math.random() * (high - low);
}
/*
Receives a number and returns its CSS pixel value.
*/
function pixelValue(value) {
return value 'px';
}
/*
Returns a duration value for the falling animation.
*/
function durationValue(value) {
return value 's';
}
/*
Uses an img element to create each leaf. "Leaves.css" implements two spin
animations for the leaves: clockwiseSpin and counterclockwiseSpinAndFlip. This
function determines which of these spin animations should be applied to each leaf.
*/
function createALeaf() {
/* Start by creating a wrapper div, and an empty img element */
var leafDiv = document.createElement('div');
var image = document.createElement('img');
/* Randomly choose a leaf image and assign it to the newly created element */
image.src ='images/hb/petal' randomInteger(1, 10) '.png';
/* Position the leaf at a random location along the screen */
leafDiv.style.top = pixelValue(randomInteger(-200, -100));
leafDiv.style.left = pixelValue(randomInteger(0, 1920));
/* Randomly choose a spin animation */
var spinAnimationName = (Math.random() < 0.5) ? 'clockwiseSpin':'counterclockwiseSpinAndFlip'; /* Set the -webkit-animation-name property with these values */
leafDiv.style.webkitAnimationName ='fade, drop';
leafDiv.style.animationName ='fade, drop';
image.style.webkitAnimationName = spinAnimationName;
image.style.animationName = spinAnimationName;
/* 随机下落时间 */
var fadeAndDropDuration = durationValue(randomFloat(1.2, 8.2));
/* 随机旋转时间 */
var spinDuration = durationValue(randomFloat(3, 4));
leafDiv.style.webkitAnimationDuration = fadeAndDropDuration ', ' fadeAndDropDuration;
leafDiv.style.animationDuration = fadeAndDropDuration ', ' fadeAndDropDuration;
// 随机delay时间
var leafDelay = durationValue(randomFloat(0, 2));
leafDiv.style.webkitAnimationDelay = leafDelay ', ' leafDelay;
leafDiv.style.animationDelay = leafDelay ', ' leafDelay;
image.style.webkitAnimationDuration = spinDuration;
image.style.animationDuration = spinDuration;
leafDiv.appendChild(image);
return leafDiv;
}
init();
setInterval(init,3000);
}
)();