首页 > 其他分享 >文字背景粒子特效

文字背景粒子特效

时间:2022-08-21 20:35:11浏览次数:59  
标签:文字 特效 rotate 粒子 translateY opacity transform 0% webkit

前言

一款jQuery+CSS3的文字背景粒子动画特效,一共6种粒子效果,每种文字背景的粒子效果都不同,有漂浮的有坠落的等等。

0x001 特效演示


This is fires This is lines This is hearts This is bubbles This is confetti This is sunbeams

0x002 Fires 特效

1. JS 代码

<script>
function fire() { 
   $.each($(".particletext.fire"), function(){ 
      var firecount = ($(this).width()/50)*20; 
      for(var i = 0; i <= firecount; i++) { 
         var size = $.rnd(8,12); 
         $(this).append('<span class="particle" style="top:' + $.rnd(40,70) + '%; left:' + $.rnd(-10,100) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + ($.rnd(0,20)/10) + 's;"></span>'); 
      } 
   }); 
} 
  jQuery.rnd = function(m,n) {
      m = parseInt(m);
      n = parseInt(n);
      return Math.floor( Math.random() * (n - m + 1) ) + m;
  }
  fire();
</script>

2. CSS 代码

<style>
.fire > .particle {
  position: absolute;
  background-color: rgba(255, 193, 7, 0.5);
  border-radius: 40px;
  border-top-right-radius: 0px;
  -webkit-animation: fires 0.8s linear infinite;
          animation: fires 0.8s linear infinite;
  -webkit-transform: rotate(-45deg);
          transform: rotate(-45deg);
  opacity: 0;
}

@-webkit-keyframes fires {
  0% {
    -webkit-transform: rotate(-70deg) translateY(0%);
            transform: rotate(-70deg) translateY(0%);
  }
  25% {
    -webkit-transform: rotate(-20deg) translateY(-5%);
            transform: rotate(-20deg) translateY(-5%);
    opacity: 1;
  }
  50% {
    -webkit-transform: rotate(-70deg) translateY(-10%);
            transform: rotate(-70deg) translateY(-10%);
  }
  75% {
    -webkit-transform: rotate(-20deg) translateY(-20%);
            transform: rotate(-20deg) translateY(-20%);
  }
  100% {
    -webkit-transform: rotate(-70deg) translateY(-40%);
            transform: rotate(-70deg) translateY(-40%);
    opacity: 1;
  }
}
@keyframes fires {
  0% {
    -webkit-transform: rotate(-70deg) translateY(0%);
            transform: rotate(-70deg) translateY(0%);
  }
  25% {
    -webkit-transform: rotate(-20deg) translateY(-5%);
            transform: rotate(-20deg) translateY(-5%);
    opacity: 1;
  }
  50% {
    -webkit-transform: rotate(-70deg) translateY(-10%);
            transform: rotate(-70deg) translateY(-10%);
  }
  75% {
    -webkit-transform: rotate(-20deg) translateY(-20%);
            transform: rotate(-20deg) translateY(-20%);
  }
  100% {
    -webkit-transform: rotate(-70deg) translateY(-40%);
            transform: rotate(-70deg) translateY(-40%);
    opacity: 1;
  }
}
</style>

3. HTML 代码

<div style="width: 100%;text-align: center; height: 120px; position: relative; bottom: 0px;" >
<span class="particletext fire" style="font-size:48px;position: relative;">This is fires</span>
</div>

0x003 Lines 特效

1. JS 代码

<script>
function lines() { 
   $.each($(".particletext.lines"), function(){ 
      var linecount = ($(this).width()/50)*10; 
      for(var i = 0; i <= linecount; i++) { 
         $(this).append('<span class="particle" style="top:' + $.rnd(-30,30) + '%; left:' + $.rnd(-10,110) + '%;width:' + $.rnd(1,3) + 'px; height:' + $.rnd(20,80) + '%;animation-delay: -' + ($.rnd(0,30)/10) + 's;"></span>'); 
      } 
   }); 
} 
  jQuery.rnd = function(m,n) {
      m = parseInt(m);
      n = parseInt(n);
      return Math.floor( Math.random() * (n - m + 1) ) + m;
  }
  lines();
</script>

2. CSS 代码

<style>
.lines > .particle {
  position: absolute;
  background-color: rgba(244, 67, 54, 0.5);
  -webkit-animation: lines 3s linear infinite;
          animation: lines 3s linear infinite;
}
@-webkit-keyframes lines {
  0%, 50%, 100% {
    -webkit-transform: translateY(0%);
            transform: translateY(0%);
  }
  25% {
    -webkit-transform: translateY(100%);
            transform: translateY(100%);
  }
  75% {
    -webkit-transform: translateY(-100%);
            transform: translateY(-100%);
  }
}
@keyframes lines {
  0%, 50%, 100% {
    -webkit-transform: translateY(0%);
            transform: translateY(0%);
  }
  25% {
    -webkit-transform: translateY(100%);
            transform: translateY(100%);
  }
  75% {
    -webkit-transform: translateY(-100%);
            transform: translateY(-100%);
  }
}
</style>

3. HTML 代码

<div style="width: 100%;text-align: center; height: 120px; position: relative; bottom: 0px;" > 
<span class="particletext lines" style="font-size:48px; position: relative;">This is lines</span>
</div>

0x004 Hearts 特效

1. JS 代码

<script>
function hearts() { 
   $.each($(".particletext.hearts"), function(){ 
      var heartcount = ($(this).width()/50)*5; 
      for(var i = 0; i <= heartcount; i++) { 
         var size = ($.rnd(60,120)/10); 
         $(this).append('<span class="particle" style="top:' + $.rnd(20,80) + '%; left:' + $.rnd(0,95) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + ($.rnd(0,30)/10) + 's;"></span>'); 
      } 
   }); 
} 
  jQuery.rnd = function(m,n) {
      m = parseInt(m);
      n = parseInt(n);
      return Math.floor( Math.random() * (n - m + 1) ) + m;
  }
  hearts();
</script>

2. CSS 代码

<style>
.hearts > .particle {
  opacity: 0;
  position: absolute;
  background-color: #cc2a5d;
  -webkit-animation: hearts 3s ease-in infinite;
          animation: hearts 3s ease-in infinite;
}
.hearts > .particle:before, .hearts > .particle:after {
  position: absolute;
  content: '';
  border-radius: 100px;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 100%;
  background-color: #cc2a5d;
}
.hearts > .particle:before {
  -webkit-transform: translateX(-50%);
          transform: translateX(-50%);
}
.hearts > .particle:after {
  -webkit-transform: translateY(-50%);
          transform: translateY(-50%);
}
@-webkit-keyframes hearts {
  0% {
    opacity: 0;
    -webkit-transform: translate(0, 0%) rotate(45deg);
            transform: translate(0, 0%) rotate(45deg);
  }
  20% {
    opacity: 0.8;
    -webkit-transform: translate(0, -20%) rotate(45deg);
            transform: translate(0, -20%) rotate(45deg);
  }
  100% {
    opacity: 0;
    -webkit-transform: translate(0, -1000%) rotate(45deg);
            transform: translate(0, -1000%) rotate(45deg);
  }
}
@keyframes hearts {
  0% {
    opacity: 0;
    -webkit-transform: translate(0, 0%) rotate(45deg);
            transform: translate(0, 0%) rotate(45deg);
  }
  20% {
    opacity: 0.8;
    -webkit-transform: translate(0, -20%) rotate(45deg);
            transform: translate(0, -20%) rotate(45deg);
  }
  100% {
    opacity: 0;
    -webkit-transform: translate(0, -1000%) rotate(45deg);
            transform: translate(0, -1000%) rotate(45deg);
  }
}
</style>

3. HTML 代码

<div style="width: 100%;text-align: center; height: 120px; position: relative; bottom: 0px;" >
<span class="particletext hearts" style="font-size:48px; position: relative;">This is hearts</span>
</div>

0x005 Bubbles 特效

1. JS 代码

<script>
function bubbles() { 
   $.each($(".particletext.bubbles"), function(){ 
      var bubblecount = ($(this).width()/50)*10; 
      for(var i = 0; i <= bubblecount; i++) { 
         var size = ($.rnd(40,80)/10); 
         $(this).append('<span class="particle" style="top:' + $.rnd(20,80) + '%; left:' + $.rnd(0,95) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + ($.rnd(0,30)/10) + 's;"></span>'); 
      } 
   }); 
} 
  jQuery.rnd = function(m,n) {
      m = parseInt(m);
      n = parseInt(n);
      return Math.floor( Math.random() * (n - m + 1) ) + m;
  }
  bubbles();
</script>

2. CSS 代码

<style>
<style>
.bubbles > .particle {
  opacity: 0;
  position: absolute;
  background-color: rgba(33, 150, 243, 0.5);
  -webkit-animation: bubbles 3s ease-in infinite;
          animation: bubbles 3s ease-in infinite;
  border-radius: 100%;
}
@-webkit-keyframes bubbles {
  0% {
    opacity: 0;
  }
  20% {
    opacity: 1;
    -webkit-transform: translate(0, -20%);
            transform: translate(0, -20%);
  }
  100% {
    opacity: 0;
    -webkit-transform: translate(0, -1000%);
            transform: translate(0, -1000%);
  }
}

@keyframes bubbles {
  0% {
    opacity: 0;
  }
  20% {
    opacity: 1;
    -webkit-transform: translate(0, -20%);
            transform: translate(0, -20%);
  }
  100% {
    opacity: 0;
    -webkit-transform: translate(0, -1000%);
            transform: translate(0, -1000%);
  }
}
</style>

3. HTML 代码

<div style="width: 100%;text-align: center; height: 120px; position: relative; bottom: 0px;" > 
<span class="particletext bubbles" style="font-size:48px; position: relative;">This is bubbles</span>
</div>

0x006 Confetti 特效

1. JS 代码

<script>
function confetti() { 
   $.each($(".particletext.confetti"), function(){ 
      var confetticount = ($(this).width()/50)*10; 
      for(var i = 0; i <= confetticount; i++) { 
         $(this).append('<span class="particle c' + $.rnd(1,2) + '" style="top:' + $.rnd(10,50) + '%; left:' + $.rnd(0,100) + '%;width:' + $.rnd(6,8) + 'px; height:' + $.rnd(3,4) + 'px;animation-delay: ' + ($.rnd(0,30)/10) + 's;"></span>'); 
      } 
   }); 
} 
  jQuery.rnd = function(m,n) {
      m = parseInt(m);
      n = parseInt(n);
      return Math.floor( Math.random() * (n - m + 1) ) + m;
  }
  confetti();
</script>

2. CSS 代码

<style>
.confetti > .particle {
  opacity: 0;
  position: absolute;
  -webkit-animation: confetti 3s ease-in infinite;
          animation: confetti 3s ease-in infinite;
}
.confetti > .particle.c1 {
  background-color: rgba(76, 175, 80, 0.5);
}
.confetti > .particle.c2 {
  background-color: rgba(156, 39, 176, 0.5);
}
@-webkit-keyframes confetti {
  0% {
    opacity: 0;
    -webkit-transform: translateY(0%) rotate(0deg);
            transform: translateY(0%) rotate(0deg);
  }
  10% {
    opacity: 1;
  }
  35% {
    -webkit-transform: translateY(-800%) rotate(270deg);
            transform: translateY(-800%) rotate(270deg);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    -webkit-transform: translateY(2000%) rotate(1440deg);
            transform: translateY(2000%) rotate(1440deg);
  }
}
@keyframes confetti {
  0% {
    opacity: 0;
    -webkit-transform: translateY(0%) rotate(0deg);
            transform: translateY(0%) rotate(0deg);
  }
  10% {
    opacity: 1;
  }
  35% {
    -webkit-transform: translateY(-800%) rotate(270deg);
            transform: translateY(-800%) rotate(270deg);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    -webkit-transform: translateY(2000%) rotate(1440deg);
            transform: translateY(2000%) rotate(1440deg);
  }
}
</style>

3. HTML 代码

<div style="width: 100%;text-align: center; height: 120px; position: relative; bottom: 0px;" > 
<span class="particletext confetti" style="font-size:48px; position: relative;">This is confetti</span>
</div>

0x007 Sunbeams 特效

1. JS 代码

<script>
function sunbeams() { 
   $.each($(".particletext.sunbeams"), function(){ 
      var linecount = ($(this).width()/50)*10; 
      for(var i = 0; i <= linecount; i++) { 
         $(this).append('<span class="particle" style="top:' + $.rnd(-50,00) + '%; left:' + $.rnd(0,100) + '%;width:' + $.rnd(1,3) + 'px; height:' + $.rnd(80,160) + '%;animation-delay: -' + ($.rnd(0,30)/10) + 's;"></span>'); 
      } 
   }); 
} 
  jQuery.rnd = function(m,n) {
      m = parseInt(m);
      n = parseInt(n);
      return Math.floor( Math.random() * (n - m + 1) ) + m;
  }
  sunbeams();
</script>

2. CSS 代码

<style>
.sunbeams > .particle {
  position: absolute;
  background-color: rgba(253, 216, 53, 0.5);
  -webkit-animation: sunbeams 3s linear infinite;
          animation: sunbeams 3s linear infinite;
}
@-webkit-keyframes sunbeams {
  0% {
    -webkit-transform: translateY(40%) rotate(0deg);
            transform: translateY(40%) rotate(0deg);
  }
  50% {
    -webkit-transform: translateY(-40%) rotate(180deg);
            transform: translateY(-40%) rotate(180deg);
  }
  100% {
    -webkit-transform: translateY(40%) rotate(360deg);
            transform: translateY(40%) rotate(360deg);
  }
  0%,14%,17%,43%,53%,71%,80%,94%,100% {
    opacity: 0;
  }
  6%,15%,24%,28%,48%,55%,78%,82%,99% {
    opacity: 1;
  }
}
@keyframes sunbeams {
  0% {
    -webkit-transform: translateY(40%) rotate(0deg);
            transform: translateY(40%) rotate(0deg);
  }
  50% {
    -webkit-transform: translateY(-40%) rotate(180deg);
            transform: translateY(-40%) rotate(180deg);
  }
  100% {
    -webkit-transform: translateY(40%) rotate(360deg);
            transform: translateY(40%) rotate(360deg);
  }
  0%,14%,17%,43%,53%,71%,80%,94%,100% {
    opacity: 0;
  }
  6%,15%,24%,28%,48%,55%,78%,82%,99% {
    opacity: 1;
  }
}
</style>

3. HTML 代码

<div style="width: 100%;text-align: center; height: 120px; position: relative; bottom: 0px;" >
<span class="particletext sunbeams" style="font-size:48px; position: relative;">This is sunbeams</span>
</div>

标签:文字,特效,rotate,粒子,translateY,opacity,transform,0%,webkit
From: https://www.cnblogs.com/wdysblog/p/16610787.html

相关文章

  • div内多行文字, 溢出部分用省略号显示
     1/*内容*/2.content{3width:100%;4height:70px;5font-size:small;6margin-top:10px;78text-overflow:-o-ellipsis-lastline;9......
  • HTML之marquee(文字滚动)详解
    https://www.cnblogs.com/smiler/p/4892918.html语法:<marquee></marquee>以下是一个最简单的例子:代码如下:<marquee><fontsize=+3color=red>Hello,World</font><......
  • 绘文字emoji
    最近有个webservice报错,原因是穿了一些非法字符。一问,用户手机填了表情包--绘文字,emoji处理绘文字,还得看日本人,emoji就是绘文字的日语发音。。。倒不一定是他们发明的,但......
  • 字母-英文字母怎么产生的:一千字带你了解字母的起源和发展
    参考:https://baijiahao.baidu.com/s?id=1723733095013625072&wfr=spider&for=pc 在世界历史上,约公元前3500年就出现文字,最早出现的是古埃及的象形文字,也有人说是苏美......
  • php 图片添加文字水印 以及 图片合成(微信快码传播)
    1、图片添加文字水印:12345678910111213141516171819202122232425262728293031$bigImgPath = 'backgroud.png';    $img......
  • win32com:word操作之 通过文字查找段落
      练习:#遍历可以查找出所有包含关键字的段落#去掉遍历只查找到第一个包含关键字的段落fullrange=doc.Range()foriinrange(4):fullrange.Find.Execut......
  • [办公自动化]如何把mp3转换为文字?
    有的时候,我们需要把录音转为文字稿。今天介绍一个好办法,希望能够帮助到你。首先你需要有一个163的帐号。然后按如下步骤操作即可:1、登陆见外工作台。https://jianwai.y......
  • Oracle 解决【ORA-01704:字符串文字太长】
    错误提示:oracle在toad中执行一段sql语句时,出现错误‘ORA-01704:字符串文字太长’。如下图:原因:一般为包含有对CLOB字段的数据操作。如果CLOB字段的内容非常大的时候,会导致S......
  • css实现按钮边框流动特效
      .my_btn{width:100px;height:50px;text-align:center;margin-top:10px;line-height:50px;background-color:#fff;position:relative......
  • 输入文字的完善
    //3.文本域字数不得超过限制获取输入框consttextarea=document.querySelector('.comm-inputtextarea')//3.1中文起始量为falseletisChinese=falsetextare......