首页 > 网站脚本

变形粒子动画

应用平台:PC + 移动

   凡库  No.01
网站样式兼容性
样式描述:可变形粒子动画效果

可变形粒子动画效果,凡库网

友情提示:文件压缩包若带有密码,均为:www.changfanku.com

部分代码段

<div id="jsi-particle-container" class="container"></div>
<script>
var RENDERER = {
    PARTICLE_COUNT : 700,
    PARTICLE_RADIUS : 1,
    MAX_ROTATION_ANGLE : Math.PI / 60,
    TRANSLATION_COUNT : 500,

    init : function(strategy){
        this.setParameters(strategy);
        this.createParticles();
        this.setupFigure();
        this.reconstructMethod();
        this.bindEvent();
        this.drawFigure();
    },
    setParameters : function(strategy){
        this.$window = $(window);

        this.$container = $('#jsi-particle-container');
        this.width = this.$container.width();
        this.height = this.$container.height();

        this.$canvas = $('<canvas />').attr({width : this.width, height : this.height}).appendTo(this.$container);
        this.context = this.$canvas.get(0).getContext('2d');

        this.center = {x : this.width / 2, y : this.height / 2};

        this.rotationX = this.MAX_ROTATION_ANGLE;
        this.rotationY = this.MAX_ROTATION_ANGLE;
        this.strategyIndex = 0;
        this.translationCount = 0;
        this.theta = 0;

        this.strategies = strategy.getStrategies();
        this.particles = [];
    },
    createParticles : function(){
        for(var i = 0; i < this.PARTICLE_COUNT; i ++){
            this.particles.push(new PARTICLE(this.center));
        }
    },
    reconstructMethod : function(){
        this.setupFigure = this.setupFigure.bind(this);
        this.drawFigure = this.drawFigure.bind(this);
        this.changeAngle = this.changeAngle.bind(this);
    },
    bindEvent : function(){
        this.$container.on('click', this.setupFigure);
        this.$container.on('mousemove', this.changeAngle);
    },
    changeAngle : function(event){
        var offset = this.$container.offset(),
            x = event.clientX - offset.left + this.$window.scrollLeft(),
            y = event.clientY - offset.top + this.$window.scrollTop();

        this.rotationX = (this.center.y - y) / this.center.y * this.MAX_ROTATION_ANGLE;
        this.rotationY = (this.center.x - x) / this.center.x * this.MAX_ROTATION_ANGLE;
    },
    setupFigure : function(){
        for(var i = 0, length = this.particles.length; i < length; i++){
            this.particles[i].setAxis(this.strategies[this.strategyIndex]());
        }
        if(++this.strategyIndex == this.strategies.length){
            this.strategyIndex = 0;
        }
        this.translationCount = 0;
    },
    drawFigure : function(){
        requestAnimationFrame(this.drawFigure);

        this.context.fillStyle = 'rgba(0, 0, 0, 0.2)';
        this.context.fillRect(0, 0, this.width, this.height);

        for(var i = 0, length = this.particles.length; i < length; i++){
            var axis = this.particles[i].getAxis2D(this.theta);

            this.context.beginPath();
            this.context.fillStyle = axis.color;
            this.context.arc(axis.x, axis.y, this.PARTICLE_RADIUS, 0, Math.PI * 2, false);
            this.context.fill();
        }
        this.theta++;
        this.theta %= 360;

        for(var i = 0, length = this.particles.length; i < length; i++){
            this.particles[i].rotateX(this.rotationX);
            this.particles[i].rotateY(this.rotationY);
        }
        this.translationCount++;
        this.translationCount %= this.TRANSLATION_COUNT;

        if(this.translationCount == 0){
            this.setupFigure();
        }
    }
};
推荐样式

DEMO.科技服务公司网站样式

一家科技服务公司网站样式,深色系,灰色主题色。
  科技广告
 184  ¥8000元

DEMO.新能源公司网站模板

一款新能源集团网站样式,大气、简洁。
  工业化工
 251  ¥8000元

DEMO.游戏公司网站样式

一款游戏公司网站样式,黑色、深色系。
  科技广告
 475  ¥8000元

DEMO.黑色科技材料网站样式

黑色科技网站样式
  科技广告
 596  ¥8000元

微信扫一扫

学习更多的网络营销知识

海量网站任你选~