限时优惠活动
亲爱的苦力吧用户,我们为了回馈新老用户一直以来的鼎力支持,即日起(2025-02-06至2025-03-06)凡是购买苦力吧VIP/充值K币的新老用户,都直接可获得买一送一的优惠馈赠。例如:购买一个月的VIP会员可直接获得两个月的VIP会员;充值100K币可直接获得200K币,以此类推!有任何疑问可联系在线客服,感谢各位用户对苦力吧素材的信任与厚爱,我们将一如既往的给大家上新更多优质的素材源码,祝大家开工大吉、工作顺利、心想事成。

jquery粒子动画文字特效代码

所属分类: 网页特效-动画效果    2024-10-10 02:20:26

jquery粒子动画文字特效代码 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

jquery粒子动画文字特效代码(共5个文件)

    • index.html

使用方法

function PointText() {

    /***
     * 初始化点文本
     * @param text
     * @param dom
     * @param width
     * @param height
     * @param font
     * @param color
     * @param gap
     * @returns {PointText}
     */
    PointText.initPointText = function (text,dom,width,height,font,color,gap) {
        text = text? text : "";
        dom = dom? dom : "canvas";
        width = width? width : "";
        height = height? height : "";
        font = font? font : `${10 * devicePixelRatio}rem 'Arial'`;
        color = color? color : 'rgba(102,204,153,0.36)';
        gap = gap? gap : 5;
        class PointText {
            constructor(text,dom,width,height,font,color,gap){
                this.nowText = text;
                this.newText = null;
                this.dom = dom;
                this.canvas = document.querySelector(dom);
                this.font=font;
                this.color=color;
                this.gap=gap;
                this.ctx = this.canvas.getContext('2d', {
                    willReadFrequently: true,
                });
                this.canvas.width = width * devicePixelRatio;
                this.canvas.height = height * devicePixelRatio;
                this.particles = [];
                this.initDraw = this.initDraw.bind(this);
            }
            initParticle(ca,ct,co) {
                class Particle {
                    constructor(canvas,ctx,color){
                        this.ctx = ctx;
                        this.color = color;
                        this.size = this.getRandom(2 * devicePixelRatio, 7 * devicePixelRatio);
                        const r = Math.min(canvas.width,canvas.height) / 2;
                        const rad = (this.getRandom(0,360)* Math.PI)/ 180;
                        const cx = canvas.width /2;
                        const cy = canvas.height / 2;
                        this.x = cx + r * Math.cos(rad);
                        this.y = cy + r * Math.sin(rad);
                    }
                    getRandom(min,max){
                        return Math.floor(Math.random() *(max + 1 - min)+min);
                    }
                    moveTo(tx, ty){
                        const duration = 500;
                        const sx = this.x, sy = this.y;
                        const xSpeed = (tx - sx) /duration;
                        const ySpeed = (ty - sy) / duration;
                        const startTime = Date.now();
                        const _move = () => {
                            const t = Date.now() - startTime;
                            const x = sx + xSpeed * t;
                            const y = sy + ySpeed * t;
                            this.x = x;
                            this.y = y;
                            if (t >= duration) {
                                this.x = tx;
                                this.y = ty;
                                return;
                            }
                            requestAnimationFrame(_move);
                        }
                        _move();
                    }
                    draw(){
                        this.ctx.beginPath();
                        this.ctx.arc(this.x,this.y, this.size,0,2 * Math.PI);
                        this.ctx.fillStyle=this.color;
                        this.ctx.fill();
                    }
                }
                return new Particle(ca,ct,co);
            }
            getPoints() {
                let points = [];
                const  {data} =this.ctx.getImageData(0,0,this.canvas.width,this.canvas.height);
                for(let i=0;i<this.canvas.width;i+=this.gap) {
                    for (let j = 0; j < this.canvas.height; j+=this.gap) {
                        const index = (i + j * this.canvas.width) * 4;
                        const r = data[index];
                        const g = data[index + 1];
                        const b = data[index + 2];
                        const a = data[index + 3];
                        if(r ===0 && g===0 && b===0 && a===255){
                            points.push([i,j]);
                        }
                    }
                }
                return points;
            }
            update(){
                if(this.nowText!== this.newText){
                    this.newText = this.nowText;
                    const {width,height}=this.canvas;
                    this.ctx.textBaseline='middle';
                    this.ctx.font=this.font;
                    this.ctx.textAlign ='center';
                    this.ctx.fillStyle='#000';
                    this.ctx.fillText(this.nowText,width / 2,height / 2);
                    const points = this.getPoints();
                    this.clear();
                    for(let i=0;i<points.length;i++){
                        const [x,y]=points[i];
                        let p = this.particles[i];
                        if(!p){
                            p= this.initParticle(this.canvas,this.ctx,this.color);
                            this.particles.push(p);
                        }
                        p.moveTo(x,y);

                    }
                    if(points.length <this.particles.length){
                        this.particles.splice(points.length);
                    }
                }
            }
            setText(text){
                this.nowText = text;
            }
            setFont(font){
                this.font = font;
            }
            setColor(color){
                this.particles = [];
                this.color = color;
            }
            resetSize(width,height,font){
                this.canvas.width = width * devicePixelRatio;
                this.canvas.height = height * devicePixelRatio;
                this.font = font;
            }
            clear(){
                this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height);
            }
            initDraw(){
                this.clear();
                this.update();
                this.particles.forEach(p=>p.draw());
                if(document.querySelector(this.dom) !== null){
                    requestAnimationFrame(this.initDraw);
                }
            }
        }
        const pointText = new PointText(text,dom,width,height,font,color,gap);
        pointText.initDraw();
        return pointText;
    }
}

new PointText();

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 动画效果

jquery跟随鼠标转动的眼睛动画特效

一款模拟人类眼睛转动眨眼动画特效代码,眼珠跟随鼠标轨迹转动,非常有趣!
  动画效果
 6340  0

jquery跟随鼠标多彩气泡动画特效

一款鼠标跟随动画特效,当移动或者点击鼠标时,鼠标周围即会出现许多大小不一的气泡,并且这些气泡跟随鼠标一起滑动,一段时间内气泡就会逐渐破灭。另外,还可通过鼠标右键来控制背景图案以及选择是否开启气泡动画。
  动画效果
 499  0

jquery带多种文本文字切换动画特效代码

一款文本文字切换动画插件,包含7种CSS3支持的平滑过渡效果,非常的漂亮。
  动画效果
 6292  0

jquery+CSS3动感实用的10种风格进度条插件

一款实用好看的进度条插件,充分利用了CSS3的特性,让进度条外观显得非常时尚漂亮,共包含了10种风格样式,非常实用。
  动画效果
 983  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论