限时优惠活动
亲爱的苦力吧用户,我们为了回馈新老用户一直以来的鼎力支持,即日起(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

使用方法

  • code
  • source
  1. function PointText() {
  2. /***
  3. * 初始化点文本
  4. * @param text
  5. * @param dom
  6. * @param width
  7. * @param height
  8. * @param font
  9. * @param color
  10. * @param gap
  11. * @returns {PointText}
  12. */
  13. PointText.initPointText = function (text,dom,width,height,font,color,gap) {
  14. text = text? text : "";
  15. dom = dom? dom : "canvas";
  16. width = width? width : "";
  17. height = height? height : "";
  18. font = font? font : `${10 * devicePixelRatio}rem 'Arial'`;
  19. color = color? color : 'rgba(102,204,153,0.36)';
  20. gap = gap? gap : 5;
  21. class PointText {
  22. constructor(text,dom,width,height,font,color,gap){
  23. this.nowText = text;
  24. this.newText = null;
  25. this.dom = dom;
  26. this.canvas = document.querySelector(dom);
  27. this.font=font;
  28. this.color=color;
  29. this.gap=gap;
  30. this.ctx = this.canvas.getContext('2d', {
  31. willReadFrequently: true,
  32. });
  33. this.canvas.width = width * devicePixelRatio;
  34. this.canvas.height = height * devicePixelRatio;
  35. this.particles = [];
  36. this.initDraw = this.initDraw.bind(this);
  37. }
  38. initParticle(ca,ct,co) {
  39. class Particle {
  40. constructor(canvas,ctx,color){
  41. this.ctx = ctx;
  42. this.color = color;
  43. this.size = this.getRandom(2 * devicePixelRatio, 7 * devicePixelRatio);
  44. const r = Math.min(canvas.width,canvas.height) / 2;
  45. const rad = (this.getRandom(0,360)* Math.PI)/ 180;
  46. const cx = canvas.width /2;
  47. const cy = canvas.height / 2;
  48. this.x = cx + r * Math.cos(rad);
  49. this.y = cy + r * Math.sin(rad);
  50. }
  51. getRandom(min,max){
  52. return Math.floor(Math.random() *(max + 1 - min)+min);
  53. }
  54. moveTo(tx, ty){
  55. const duration = 500;
  56. const sx = this.x, sy = this.y;
  57. const xSpeed = (tx - sx) /duration;
  58. const ySpeed = (ty - sy) / duration;
  59. const startTime = Date.now();
  60. const _move = () => {
  61. const t = Date.now() - startTime;
  62. const x = sx + xSpeed * t;
  63. const y = sy + ySpeed * t;
  64. this.x = x;
  65. this.y = y;
  66. if (t >= duration) {
  67. this.x = tx;
  68. this.y = ty;
  69. return;
  70. }
  71. requestAnimationFrame(_move);
  72. }
  73. _move();
  74. }
  75. draw(){
  76. this.ctx.beginPath();
  77. this.ctx.arc(this.x,this.y, this.size,0,2 * Math.PI);
  78. this.ctx.fillStyle=this.color;
  79. this.ctx.fill();
  80. }
  81. }
  82. return new Particle(ca,ct,co);
  83. }
  84. getPoints() {
  85. let points = [];
  86. const {data} =this.ctx.getImageData(0,0,this.canvas.width,this.canvas.height);
  87. for(let i=0;i<this.canvas.width;i+=this.gap) {
  88. for (let j = 0; j < this.canvas.height; j+=this.gap) {
  89. const index = (i + j * this.canvas.width) * 4;
  90. const r = data[index];
  91. const g = data[index + 1];
  92. const b = data[index + 2];
  93. const a = data[index + 3];
  94. if(r ===0 && g===0 && b===0 && a===255){
  95. points.push([i,j]);
  96. }
  97. }
  98. }
  99. return points;
  100. }
  101. update(){
  102. if(this.nowText!== this.newText){
  103. this.newText = this.nowText;
  104. const {width,height}=this.canvas;
  105. this.ctx.textBaseline='middle';
  106. this.ctx.font=this.font;
  107. this.ctx.textAlign ='center';
  108. this.ctx.fillStyle='#000';
  109. this.ctx.fillText(this.nowText,width / 2,height / 2);
  110. const points = this.getPoints();
  111. this.clear();
  112. for(let i=0;i<points.length;i++){
  113. const [x,y]=points[i];
  114. let p = this.particles[i];
  115. if(!p){
  116. p= this.initParticle(this.canvas,this.ctx,this.color);
  117. this.particles.push(p);
  118. }
  119. p.moveTo(x,y);
  120. }
  121. if(points.length <this.particles.length){
  122. this.particles.splice(points.length);
  123. }
  124. }
  125. }
  126. setText(text){
  127. this.nowText = text;
  128. }
  129. setFont(font){
  130. this.font = font;
  131. }
  132. setColor(color){
  133. this.particles = [];
  134. this.color = color;
  135. }
  136. resetSize(width,height,font){
  137. this.canvas.width = width * devicePixelRatio;
  138. this.canvas.height = height * devicePixelRatio;
  139. this.font = font;
  140. }
  141. clear(){
  142. this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height);
  143. }
  144. initDraw(){
  145. this.clear();
  146. this.update();
  147. this.particles.forEach(p=>p.draw());
  148. if(document.querySelector(this.dom) !== null){
  149. requestAnimationFrame(this.initDraw);
  150. }
  151. }
  152. }
  153. const pointText = new PointText(text,dom,width,height,font,color,gap);
  154. pointText.initDraw();
  155. return pointText;
  156. }
  157. }
  158. new PointText();
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+CSS3实现网页元素抖动特效

一款鼠标悬停触发的CSS3动画特效,可以让网页上任何元素进行抖动,抖动参数可自定义设置。可以定义抖动的速度快慢、方向以及更为复杂的抖动效果。
  动画效果
 8264  0

jquery盆栽绿植生长动画特效

一款植物生长过程动画效果,可自定义添加新的行动计划,列表中的计划选中后可触发右侧绿植生长。
  动画效果
 8171  0

jquery鼠标悬停显示跟随浮动图片

一款悬停显示鼠标跟随图片特效,鼠标悬停在文本文字上,显示跟随鼠标光标移动的浮动图片,非常有意思。
  动画效果
 4221  0

jquery鼠标点击DIV触发波纹动画特效插件

一款轻量级波纹动画插件,当鼠标点击按钮或指定的任何DIV元素时,将会触发Material Design波纹效果。
  动画效果
 4468  0

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

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