文本/链接

js+css炫酷3D立体卡通文字特效

阿里云


这是一款效果使用纯 js 和 CSS3 制作的炫酷 3D 立体卡通文字特效。该特效通过 js 代码来克隆字母的内容,并通过 CSS text-shadow 属性和 transform 属性将字母渲染为 3D 立体效果。

HTML 结构:

该 3D 立体文字特效的 HTML 代码非常简单,使用一个[div]来包裹文字即可。

也想出现在这里?联系我们
创客主机
  1. <div class="wrapper">
  2.   <div class="content">
  3.     Alphabet Magnet Text Styling
  4.   </div>
  5. </div>

CSS 样式:

该 3D 立体文字特效的 CSS 代码如下:

  1. .content {
  2.   font-family: 'Rubik';
  3.   font-size: 6rem;
  4.   font-weight: 900;
  5.   letter-spacing: .04em;
  6.   display: block;
  7.   word-spacing: 3rem;
  8.   line-height: 1.4;
  9.   text-transform: uppercase;
  10. }
  11. .content div {
  12.   display: inline;
  13. }
  14. .content span {
  15.   display: inline-block;
  16. }
  17. .content span:hover {
  18.   animation: wobble 200ms;
  19. }
  20. .content span:nth-child(1n) {
  21.   color: #F18829;
  22.   text-shadow: #ef7b11 1px 1px, #f7bd89 -1px -1px, #f37841 -2px -2px 6px, #f49d4f -2px -2px, #f49d4f -1px -2px, #f49d4f -1px -3px, #f49d4f -2px -4px, #f49d4f -2px -5px, #f49d4f -3px -6px, #F18829 -4px -7px, rgba(0, 0, 5, 0.4) 3px 4px 5px, rgba(0, 0, 5, 0.2) -3px -4px 5px;
  23.   transform: rotate(-3deg);
  24. }
  25. .content span:nth-child(2n) {
  26.   color: #00B9ED;
  27.   text-shadow: #00a5d4 1px 1px, #54d9ff -1px -1px, #08f2ff -2px -2px 6px, #17ccff -2px -2px, #17ccff -1px -2px, #17ccff -1px -3px, #17ccff -2px -4px, #17ccff -2px -5px, #17ccff -3px -6px, #00B9ED -4px -7px, rgba(0, 0, 5, 0.4) 3px 4px 5px, rgba(0, 0, 5, 0.2) -3px -4px 5px;
  28.   transform: rotate(3deg) translateY(4%);
  29. }
  30. .content span:nth-child(3n) {
  31.   color: #ED5053;
  32.   text-shadow: #eb393c 1px 1px, #f7acae -1px -1px, #ef6780 -2px -2px 6px, #f17577 -2px -2px, #f17577 -1px -2px, #f17577 -1px -3px, #f17577 -2px -4px, #f17577 -2px -5px, #f17577 -3px -6px, #ED5053 -4px -7px, rgba(0, 0, 5, 0.4) 3px 4px 5px, rgba(0, 0, 5, 0.2) -3px -4px 5px;
  33.   transform: rotate(-3deg);
  34. }
  35. .content span:nth-child(4n) {
  36.   color: #00AF4F;
  37.   text-shadow: #009643 1px 1px, #16ff7f -1px -1px, #00c939 -2px -2px 6px, #00d861 -2px -2px, #00d861 -1px -2px, #00d861 -1px -3px, #00d861 -2px -4px, #00d861 -2px -5px, #00d861 -3px -6px, #00AF4F -4px -7px, rgba(0, 0, 5, 0.4) 3px 4px 5px, rgba(0, 0, 5, 0.2) -3px -4px 5px;
  38.   transform: rotate(-2deg);
  39. }
  40. .content span:nth-child(5n) {
  41.   color: #8E509F;
  42.   text-shadow: #7f478e 1px 1px, #ba8fc6 -1px -1px, #8e5cad -2px -2px 6px, #a266b2 -2px -2px, #a266b2 -1px -2px, #a266b2 -1px -3px, #a266b2 -2px -4px, #a266b2 -2px -5px, #a266b2 -3px -6px, #8E509F -4px -7px, rgba(0, 0, 5, 0.4) 3px 4px 5px, rgba(0, 0, 5, 0.2) -3px -4px 5px;
  43.   transform: rotate(3deg) translateY(-2%);
  44. }
  45. .content span:nth-child(6n) {
  46.   color: #F9DE00;
  47.   text-shadow: #e0c700 1px 1px, #ffee60 -1px -1px, #ffbe14 -2px -2px 6px, #ffe723 -2px -2px, #ffe723 -1px -2px, #ffe723 -1px -3px, #ffe723 -2px -4px, #ffe723 -2px -5px, #ffe723 -3px -6px, #F9DE00 -4px -7px, rgba(0, 0, 5, 0.4) 3px 4px 5px, rgba(0, 0, 5, 0.2) -3px -4px 5px;
  48.   transform: rotate(5deg) translateY(1%);
  49. }
  50.  
  51. @keyframes wobble {
  52.   50% {
  53.     transform: translate(2%, 2%);
  54.   }
  55. }

JavaScript 代码:

JS 代码的左右主要是克隆字母的内容。代码如下:

  1. 'use strict';
  2. var container = document.querySelector('.content');
  3. var content = container.innerText;
  4.  
  5. function formatContent(content, container) {
  6.   var contentArray = content.split(' ');
  7.   var formattedContent = document.createElement('div');
  8.   contentArray.map(function (word) {
  9.     formattedContent.appendChild(createWord(word));
  10.   });
  11.   console.log(contentArray);
  12.  
  13.   container.replaceChild(formattedContent, container.firstChild);
  14. };
  15.  
  16. function createWord(characters) {
  17.   var word = document.createElement('div');
  18.   var wordArray = characters.split('');
  19.   wordArray.map(function (char) {
  20.     word.appendChild(formatCharacter(char));
  21.   });
  22.   word.appendChild(formatCharacter(' '));
  23.   return word;
  24. }
  25.  
  26. function formatCharacter(text) {
  27.   var text = text === ' ' ? ' ' : text;
  28.   var character = document.createElement('span');
  29.   character.innerHTML = text;
  30.   return character;
  31. }
  32.  
  33. formatContent(content, container);

js+css 炫酷 3D 立体卡通文字特效

已有 735 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!