html斜正方形,HTML5 平行交叉斜方格

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

$(function() {

var defile = new Defile();

defile.init();

});

var Defile = function() {

this.$container = $('#container');

this.colors = ['#00698B', '#0099CB', '#00394B', '#00A3D8', '#0086B1'];

this.lastColor = '';

this.nbLines = 10;

this.nbElements = 8;

this.minDuration = 2;

this.maxDuration = 4;

this.maxDelay = 2;

}

Defile.prototype = {

init: function() {

for (i = 0; i < this.nbLines; i += 1) {

this.createLine(i);

}

},

getRandomColor: function() {

color = this.colors[Math.floor(Math.random() * this.colors.length)];

while (color == this.lastColor) {

color = this.colors[Math.floor(Math.random() * this.colors.length)];

}

this.lastColor = color;

return color;

},

createLine: function(index) {

var $line = $('

class: 'line'

}).css({

height: 100 / this.nbLines + '%'

});

var animationDirection = 'normal';

var animationDelay = (Math.round((Math.random() * this.maxDelay) * 100) / 100);

var animationDuration = (Math.round((Math.random() * (this.maxDuration - this.minDuration) + this.minDuration) * 100) / 100) * 2;

var animationDelayBis = animationDelay + (animationDuration / 2);

if (index % 2 == 0) {

$line.addClass('odd');

animationDirection = 'reverse';

}

$halfLineOne = this.createHalfLine(animationDelayBis, animationDuration, animationDirection);

$halfLineTwo = this.createHalfLine(animationDelay, animationDuration, animationDirection);

$line.append($halfLineOne, $halfLineTwo);

this.$container.append($line);

},

fillLine: function($halfLine) {

for (j = 0; j < this.nbElements; j++) {

this.createElement().appendTo($halfLine);

}

},

createHalfLine: function(delay, duration, direction) {

var style = {

'animation-delay': delay + 's',

'animation-duration': duration + 's',

'animation-direction': direction

}

var $halfLine = $('

class: 'half-line'

}).css(style);

this.fillLine($halfLine);

return $halfLine;

},

createElement: function() {

var style = {

'background-color': this.getRandomColor(),

'width': 100 / this.nbElements + '%'

}

$element = $('

class: 'element'

}).css(style);

return $element;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值