当前位置:   article > 正文

几款炫酷的CSS代码样式_好看的css样式模板

好看的css样式模板

目录

1.Neumorphism.io

css

2.透明玻璃态生成器

3.盒子阴影

4.CSS 发光

5.渐变颜色按钮

 6.3D旋转木马

7.CSS 发光图标

8、动画标签栏


1.Neumorphism.io

css

  1. border-radius: 50px;
  2. background: #e0e0e0;
  3. box-shadow: 20px 20px 60px #bebebe,
  4. -20px -20px 60px #ffffff;

2.透明玻璃态生成器

css

  1. background: rgba( 255, 255, 255, 0.25 );
  2. box-shadow: 0 8px 32px 0 rgba( 31, 38, 135, 0.37 );
  3. backdrop-filter: blur( 1px );
  4. -webkit-backdrop-filter: blur( 1px );
  5. border-radius: 10px;
  6. border: 1px solid rgba( 255, 255, 255, 0.18 );

3.盒子阴影

代码连接

4.CSS 发光

网站链接下载源码 

5.渐变颜色按钮

下载

 6.3D旋转木马

 html

  1. <header>
  2. <h1>3D Carousel Using TweenMax.js & jQuery</h1>
  3. <h3>A pen by <a href="https://www.twitter.com/johnblazek" target="_blank">@johnblazek</a></h3>
  4. <div id="fps">Framerate: 0/60 FPS</div>
  5. </header>
  6. <div id="contentContainer" class="trans3d">
  7. <section id="carouselContainer" class="trans3d">
  8. <figure id="item1" class="carouselItem trans3d"><div class="carouselItemInner trans3d">1</div></figure>
  9. <figure id="item2" class="carouselItem trans3d"><div class="carouselItemInner trans3d">2</div></figure>
  10. <figure id="item3" class="carouselItem trans3d"><div class="carouselItemInner trans3d">3</div></figure>
  11. <figure id="item4" class="carouselItem trans3d"><div class="carouselItemInner trans3d">4</div></figure>
  12. <figure id="item5" class="carouselItem trans3d"><div class="carouselItemInner trans3d">5</div></figure>
  13. <figure id="item6" class="carouselItem trans3d"><div class="carouselItemInner trans3d">6</div></figure>
  14. <figure id="item7" class="carouselItem trans3d"><div class="carouselItemInner trans3d">7</div></figure>
  15. <figure id="item8" class="carouselItem trans3d"><div class="carouselItemInner trans3d">8</div></figure>
  16. <figure id="item9" class="carouselItem trans3d"><div class="carouselItemInner trans3d">9</div></figure>
  17. <figure id="item10" class="carouselItem trans3d"><div class="carouselItemInner trans3d">10</div></figure>
  18. <figure id="item11" class="carouselItem trans3d"><div class="carouselItemInner trans3d">11</div></figure>
  19. <figure id="item12" class="carouselItem trans3d"><div class="carouselItemInner trans3d">12</div></figure>
  20. </section>
  21. </div>

css

  1. html, body{ background-color:#1a948d; }
  2. body
  3. {
  4. background-image: url('../images/background.jpg');
  5. background-repeat: no-repeat;
  6. background-position: top center;
  7. width:100%;
  8. background-size:cover;
  9. height:100%;
  10. min-height:1000px;
  11. overflow:hidden;
  12. font-family: 'quicksandlight', Helvetica, Arial;
  13. color:#FFFFFF;
  14. text-shadow: -1px -1px 4px rgba(0, 0, 0, .35);
  15. filter: dropshadow(color=#000000, offx=1, offy=1);
  16. }
  17. header
  18. {
  19. margin-top:30px;
  20. position:absolute;
  21. z-index:5;
  22. width:420px;
  23. padding-top:10px;
  24. padding-bottom:10px;
  25. }
  26. h1{
  27. font-size:36px;
  28. letter-spacing:-2.5px;
  29. margin-left:30px;
  30. }
  31. h3{
  32. font-size:16px;
  33. letter-spacing:-1.5px;
  34. margin-top:5px;
  35. margin-left:35px;
  36. }
  37. #fps
  38. {
  39. margin-top:5px;
  40. margin-left:35px;
  41. }
  42. a
  43. {
  44. color:rgba( 255, 255, 255, .65 );
  45. text-decoration: none;
  46. }
  47. a:hover
  48. {
  49. color:rgba( 255, 255, 255, 1 );
  50. }
  51. /* hardware accelatator class */
  52. .trans3d
  53. {
  54. -webkit-transform-style: preserve-3d;
  55. -webkit-transform: translate3d(0, 0, 0);
  56. -moz-transform-style: preserve-3d;
  57. -moz-transform: translate3d(0, 0, 0);
  58. -ms-transform-style:preserve-3d;
  59. -ms-transform: translate3d(0, 0, 0);
  60. transform-style:preserve-3d;
  61. transform: translate3d(0, 0, 0);
  62. /*-webkit-backface-visibility: hidden;
  63. -moz-backface-visibility: hidden;
  64. -ms-backface-visibility:hidden;
  65. backface-visibility:hidden;*/
  66. }
  67. #contentContainer
  68. {
  69. position:absolute;
  70. margin-left:-500px;
  71. margin-top:-500px;
  72. left:50%;
  73. top:50%;
  74. width:1000px;
  75. height:1000px;
  76. }
  77. #carouselContainer
  78. {
  79. position:absolute;
  80. margin-left:-500px;
  81. margin-top:-500px;
  82. left:50%;
  83. top:50%;
  84. width:1000px;
  85. height:1000px;
  86. }
  87. .carouselItem
  88. {
  89. width:320px;
  90. height:130px;
  91. position:absolute;
  92. left:50%;
  93. top:50%;
  94. margin-left:-160px;
  95. margin-top:-90px;
  96. visibility:hidden;
  97. }
  98. .carouselItemInner
  99. {
  100. width:320px;
  101. height:130px;
  102. position:absolute;
  103. background-color:rgba(255, 255, 255, .75);
  104. border:10px solid rgba(255, 255, 255, .5);
  105. color:aqua;
  106. font-size:72px;
  107. left:50%;
  108. top:50%;
  109. margin-left:-160px;
  110. margin-top:-90px;
  111. text-align:center;
  112. padding-top:50px;
  113. }

js

  1. // set and cache variables
  2. var w, container, carousel, item, radius, itemLength, rY, ticker, fps;
  3. var mouseX = 0;
  4. var mouseY = 0;
  5. var mouseZ = 0;
  6. var addX = 0;
  7. // fps counter created by: https://gist.github.com/sharkbrainguy/1156092,
  8. // no need to create my own :)
  9. var fps_counter = {
  10. tick: function ()
  11. {
  12. // this has to clone the array every tick so that
  13. // separate instances won't share state
  14. this.times = this.times.concat(+new Date());
  15. var seconds, times = this.times;
  16. if (times.length > this.span + 1)
  17. {
  18. times.shift(); // ditch the oldest time
  19. seconds = (times[times.length - 1] - times[0]) / 1000;
  20. return Math.round(this.span / seconds);
  21. }
  22. else return null;
  23. },
  24. times: [],
  25. span: 20
  26. };
  27. var counter = Object.create(fps_counter);
  28. $(document).ready( init )
  29. function init()
  30. {
  31. w = $(window);
  32. container = $( '#contentContainer' );
  33. carousel = $( '#carouselContainer' );
  34. item = $( '.carouselItem' );
  35. itemLength = $( '.carouselItem' ).length;
  36. fps = $('#fps');
  37. rY = 360 / itemLength;
  38. radius = Math.round( (250) / Math.tan( Math.PI / itemLength ) );
  39. // set container 3d props
  40. TweenMax.set(container, {perspective:600})
  41. TweenMax.set(carousel, {z:-(radius)})
  42. // create carousel item props
  43. for ( var i = 0; i < itemLength; i++ )
  44. {
  45. var $item = item.eq(i);
  46. var $block = $item.find('.carouselItemInner');
  47. //thanks @chrisgannon!
  48. TweenMax.set($item, {rotationY:rY * i, z:radius, transformOrigin:"50% 50% " + -radius + "px"});
  49. animateIn( $item, $block )
  50. }
  51. // set mouse x and y props and looper ticker
  52. window.addEventListener( "mousemove", onMouseMove, false );
  53. ticker = setInterval( looper, 1000/60 );
  54. }
  55. function animateIn( $item, $block )
  56. {
  57. var $nrX = 360 * getRandomInt(2);
  58. var $nrY = 360 * getRandomInt(2);
  59. var $nx = -(2000) + getRandomInt( 4000 )
  60. var $ny = -(2000) + getRandomInt( 4000 )
  61. var $nz = -4000 + getRandomInt( 4000 )
  62. var $s = 1.5 + (getRandomInt( 10 ) * .1)
  63. var $d = 1 - (getRandomInt( 8 ) * .1)
  64. TweenMax.set( $item, { autoAlpha:1, delay:$d } )
  65. TweenMax.set( $block, { z:$nz, rotationY:$nrY, rotationX:$nrX, x:$nx, y:$ny, autoAlpha:0} )
  66. TweenMax.to( $block, $s, { delay:$d, rotationY:0, rotationX:0, z:0, ease:Expo.easeInOut} )
  67. TweenMax.to( $block, $s-.5, { delay:$d, x:0, y:0, autoAlpha:1, ease:Expo.easeInOut} )
  68. }
  69. function onMouseMove(event)
  70. {
  71. mouseX = -(-(window.innerWidth * .5) + event.pageX) * .0025;
  72. mouseY = -(-(window.innerHeight * .5) + event.pageY ) * .01;
  73. mouseZ = -(radius) - (Math.abs(-(window.innerHeight * .5) + event.pageY ) - 200);
  74. }
  75. // loops and sets the carousel 3d properties
  76. function looper()
  77. {
  78. addX += mouseX
  79. TweenMax.to( carousel, 1, { rotationY:addX, rotationX:mouseY, ease:Quint.easeOut } )
  80. TweenMax.set( carousel, {z:mouseZ } )
  81. fps.text( 'Framerate: ' + counter.tick() + '/60 FPS' )
  82. }
  83. function getRandomInt( $n )
  84. {
  85. return Math.floor((Math.random()*$n)+1);
  86. }

7.CSS 发光图标

  1. <html lang="en">
  2. <head>
  3. <meta charset="UTF-8">
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  5. <title>CSS glowing icons</title>
  6. <link rel="stylesheet" href="style.css">
  7. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
  8. </head>
  9. <body>
  10. <div class="container">
  11. <i class="fa fa-apple" id="apple"></i>
  12. <i class="fa fa-twitter" id="twitter"></i>
  13. <i class="fa fa-github-square github" id="github"></i>
  14. <i class="fa fa-facebook-square" id="facebook"></i>
  15. </div>
  16. </body>
  17. </html>
  1. * {
  2. margin: 0;
  3. padding: 0;
  4. }
  5. body {
  6. height: 100vh;
  7. width: 100vw;
  8. background: #18191f;
  9. }
  10. .container {
  11. display: flex;
  12. justify-content: center;
  13. align-items: center;
  14. height: 100vh;
  15. width: 100vw;
  16. }
  17. #apple,
  18. #twitter,
  19. #github,
  20. #facebook {
  21. font-size: 8em;
  22. background-color: #18191f;
  23. color: #fff;
  24. box-shadow: 2px 2px 2px #00000080, 10px 1px 12px #00000080,
  25. 2px 2px 10px #00000080, 2px 2px 3px #00000080, inset 2px 2px 10px #00000080,
  26. inset 2px 2px 10px #00000080, inset 2px 2px 10px #00000080,
  27. inset 2px 2px 10px #00000080;
  28. border-radius: 29px;
  29. padding: 11px 19px;
  30. margin: 0 40px;
  31. animation: animate 3s linear infinite;
  32. text-shadow: 0 0 50px #0072ff, 0 0 100px #0072ff, 0 0 150px #0072ff,
  33. 0 0 200px #0072ff;
  34. }
  35. #twitter {
  36. animation-delay: 0.3s;
  37. }
  38. #facebook {
  39. animation-delay: 0.7s;
  40. }
  41. #github {
  42. animation-delay: 0.1s;
  43. }
  44. @keyframes animate {
  45. from {
  46. filter: hue-rotate(0deg);
  47. }
  48. to {
  49. filter: hue-rotate(360deg);
  50. }
  51. }

8、动画标签栏

  1. html
  2. <menu class="menu">
  3. <button class="menu__item active">
  4. <div class="menu__icon" >
  5. <svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 179.1 145" >
  6. <g id="home-anm">
  7. <path stroke-linejoin="round" stroke-linecap="round" d="M70.5,80.1h40.7"/>
  8. <path d="M35,64v80"/>
  9. <path d="M145.1,143V63"/>
  10. <path stroke-linecap="round" stroke-linejoin="round" d="M24.9,70l65.7-50.7L156.3,70"/>
  11. </g>
  12. <path stroke-linejoin="round" d="M145.1,117.6v33.1c0,1.5-1.2,2.8-2.8,2.8h-28.4c-1.5,0-2.8-1.2-2.8-2.8V126c0-11.3-9.2-20.5-20.5-20.5l0,0
  13. c-11.3,0-20.5,9.2-20.5,20.5v27.5h16H37.8c-1.5,0-2.8-1.2-2.8-2.8v-34.2"/>
  14. </svg>
  15. </div>
  16. <strong class="menu__text active">home</strong>
  17. </button>
  18. <button class="menu__item">
  19. <div class="menu__icon" >
  20. <svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 179.1 145">
  21. <g id="strategy-anm" >
  22. <path d="M84.1,50.4L72,64.7c-2,2.4-5.2,3.5-8.3,3l-40.1-6.8c-3.2-0.6-5.8,2.4-4.8,5.5L42,127.9c1.2,3.6,4.6,6.1,8.4,6.1
  23. h81.6c3.9,0,7.3-2.6,8.5-6.3l21.5-61.4c0.9-3-1.7-6-4.9-5.4l-38.3,6.7c-3,0.6-6.2-0.5-8.2-2.8L97.4,50.2
  24. C93.8,46.3,87.6,46.3,84.1,50.4z"/>
  25. </g>
  26. <path stroke-linecap="round" d="M38.8,153.5h105.5"/>
  27. <path stroke-linecap="round" d="M66.8,112.5h49.5"/>
  28. <path id="strategy-cir1" stroke-width="0" fill="currentColor" d="M32.4,37.5c0,5.8-4.7,10.5-10.5,10.5s-10.5-4.7-10.5-10.5S16.1,27,21.9,27S32.4,31.7,32.4,37.5z"/>
  29. <path id="strategy-cir2" stroke-width="0" fill="currentColor" d="M102.3,23.5c0,5.8-4.7,10.5-10.5,10.5s-10.5-4.7-10.5-10.5S86,13,91.8,13S102.3,17.7,102.3,23.5z"/>
  30. <path id="strategy-cir3" stroke-width="0" fill="currentColor" d="M169.6,37.5c0,5.8-4.7,10.5-10.5,10.5s-10.5-4.7-10.5-10.5S153.3,27,159.1,27S169.6,31.7,169.6,37.5z"/>
  31. </svg>
  32. </div>
  33. <strong class="menu__text">strategy</strong>
  34. </button>
  35. <button class="menu__item">
  36. <div class="menu__icon" >
  37. <svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 179.1 145" >
  38. <g id="period-cir">
  39. <path fill="currentColor" stroke-width="0" d="M96.5,141.7c0,3.9-3.1,7-7,7s-7-3.1-7-7s3.1-7,7-7C93.4,134.6,96.5,137.8,96.5,141.7z"/>
  40. <path fill="currentColor" stroke-width="0" d="M78.2,126.7c0,3.9-3.1,7-7,7s-7-3.1-7-7c0-3.9,3.1-7,7-7S78.2,122.8,78.2,126.7z"/>
  41. <path fill="currentColor" stroke-width="0" d="M110.6,120.5c0,3.9-3.1,7-7,7s-7-3.1-7-7s3.1-7,7-7S110.6,116.6,110.6,120.5z"/>
  42. </g>
  43. <g id="period-anm">
  44. <path stroke-linecap="round" d="M30.8,24.7h118.3 M117.3,71.2l9.7-6.7c0.7-0.4,1.1-1.1,1.1-1.9V24.7H50v37.8"/>
  45. <path stroke-linecap="round" d="M149.4,153.3H30.6 M75.5,90.7l-23.1,21.2c-1.6,1.4-2.4,3.4-2.4,5.6v35.9h78.1V113"/>
  46. <g id="period-line">
  47. <path stroke-linecap="round" d="M50,62.5l40,44.2"/>
  48. <path stroke-linecap="round" d="M128.1,111.7L95.2,73.4"/>
  49. </g>
  50. </g>
  51. </svg>
  52. </div>
  53. <strong class="menu__text">period</strong>
  54. </button>
  55. <button class="menu__item">
  56. <div class="menu__icon" >
  57. <svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 179.1 145" >
  58. <path stroke-linecap="round" d="M94,139c-4.8,1.3-8.8,1.7-11.4,1.8c0,0-18.3,1.1-36.9-11.6c-1.9-1.3-4.7-3.2-7.8-6.2c-1.7-1.6-2.9-2.9-3.4-3.6
  59. c0,0-3.6-4.2-6.1-8.6c-4.6-8.4-5.4-18.9-5.5-21l0,0V75.5v-39c0-0.7,0.5-1.3,1.2-1.5l58-14.2c0.2-0.1,0.5-0.1,0.7,0l57.9,14.7
  60. c0.7,0.2,1.1,0.8,1.1,1.5v29.7"/>
  61. <path id="security-cir" stroke-linecap="round" d="M158.3,120.7c0,18.3-14.8,33.1-33.1,33.1s-33-14.8-33-33.1s14.8-33.1,33.1-33.1S158.3,102.4,158.3,120.7z"/>
  62. <g id="security-strok">
  63. <path stroke-linecap="round" d="M151.1,104.5l-25,25c-1.3,1.3-3.5,1.3-4.9,0l-9.1-9.1"/>
  64. <path stroke-linecap="round" d="M82.6,43L23.1,62.3"/>
  65. <path stroke-linecap="round" d="M82.6,68.4L23.1,87.6"/>
  66. </g>
  67. </svg>
  68. </div>
  69. <strong class="menu__text">security</strong>
  70. </button>
  71. <button class="menu__item">
  72. <div class="menu__icon" >
  73. <svg class="icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 179.1 145" >
  74. <circle cx="90.5" cy="90.2" r="19.7"/>
  75. <g id="settings-anm" >
  76. <path stroke-linejoin="round" d="M144.7,73.8l-6.2-1c-0.6-1.5-1.2-3-1.9-4.5l3.6-5.1c3.2-4.4,2.7-10.5-1.2-14.3l-7.4-7.4
  77. c-2.1-2.1-4.9-3.3-7.8-3.3c-2.3,0-4.5,0.7-6.4,2.1l-5.1,3.6c-1.6-0.7-3.2-1.4-4.8-2l-1-6.1c-0.9-5.4-5.5-9.3-10.9-9.3H85.1
  78. c-5.4,0-10,3.9-10.9,9.2L73.1,42c-1.5,0.6-3,1.2-4.5,1.9l-5-3.6c-1.9-1.4-4.1-2.1-6.5-2.1c-3,0-5.8,1.2-7.8,3.3l-7.4,7.4
  79. c-3.8,3.8-4.3,9.8-1.2,14.3l3.7,5.2c-0.7,1.5-1.3,3-1.8,4.5l-6.1,1c-5.4,0.9-9.3,5.5-9.3,10.9v10.5c0,5.4,3.9,10,9.2,10.9l6.3,1.1
  80. c0.6,1.5,1.2,3,1.9,4.5l-3.6,5c-3.2,4.4-2.7,10.5,1.2,14.3l7.4,7.4c2.1,2.1,4.9,3.3,7.8,3.3c2.3,0,4.5-0.7,6.4-2.1L69,136
  81. c1.4,0.6,2.8,1.2,4.2,1.7l1,6.2c0.9,5.4,5.5,9.3,10.9,9.3h10.5c5.4,0,10-3.9,10.9-9.2l1-6.2c1.5-0.6,3-1.2,4.5-1.9l5.1,3.6
  82. c1.9,1.4,4.1,2.1,6.5,2.1c3,0,5.7-1.2,7.8-3.3l7.4-7.4c3.8-3.8,4.3-9.8,1.2-14.3l-3.6-5.1c0.7-1.5,1.3-3,1.9-4.5l6.2-1
  83. c5.4-0.9,9.3-5.5,9.3-10.9V84.8C153.9,79.3,150.1,74.7,144.7,73.8z"/>
  84. </g>
  85. </svg>
  86. </div>
  87. <strong class="menu__text">settings</strong>
  88. </button>
  89. </menu>
  90. css
  91. @import url('https://fonts.googleapis.com/css2?family=Nunito:wght@800&display=swap');
  92. html {
  93. box-sizing: border-box ;
  94. --duration: .45s ;
  95. --cubic: cubic-bezier(0.4, 0, 0.2, 1) ;
  96. --color-1: #d5dadd ;
  97. --color-2: #51d5c2 ;
  98. }
  99. html *,
  100. html *::before,
  101. html *::after {
  102. box-sizing: inherit ;
  103. }
  104. body {
  105. margin: 0 ;
  106. height: 100vh ;
  107. display: flex ;
  108. overflow: hidden ;
  109. align-items: center ;
  110. justify-content: center ;
  111. background-color: #f0f1f1 ;
  112. font-family: 'Nunito', sans-serif ;
  113. }
  114. .menu {
  115. margin: 0 ;
  116. width: 42em ;
  117. display: flex ;
  118. height: 10.4em ;
  119. user-select: none ;
  120. position: relative ;
  121. align-items: center ;
  122. padding: 0 1.9em 2.5em ;
  123. justify-content: center ;
  124. background-color: #fefefe ;
  125. border-radius: 1em 1em 4.5em 4.5em ;
  126. -webkit-tap-highlight-color: transparent ;
  127. }
  128. @media (max-width: 42.625em) {
  129. .menu {
  130. font-size: .55em ;
  131. }
  132. }
  133. .menu::after {
  134. height: 5% ;
  135. width: 35% ;
  136. bottom: 10% ;
  137. content: " " ;
  138. position: absolute ;
  139. border-radius: 1em ;
  140. background-color: #f2f3f4 ;
  141. }
  142. .menu__item {
  143. all: unset ;
  144. flex-grow: 1 ;
  145. display: flex ;
  146. cursor: pointer ;
  147. overflow: hidden ;
  148. padding-top: 0.5em ;
  149. position: relative ;
  150. align-items: center ;
  151. color: var(--color-1) ;
  152. justify-content: center ;
  153. transition: flex-grow var(--duration) var(--cubic) ;
  154. }
  155. .menu__icon {
  156. font-size: 1.05em ;
  157. stroke: currentColor ;
  158. transition: transform var(--duration) var(--cubic) ;
  159. }
  160. .menu__item::before {
  161. top: 9% ;
  162. left: 18.4% ;
  163. width: 1.5em ;
  164. height: 1.5em ;
  165. content: " ";
  166. position: absolute ;
  167. border-radius: 50% ;
  168. transform: scale(0) ;
  169. transform-origin: center ;
  170. background-color: #fdecef ;
  171. transition: transform var(--duration) var(--cubic) ;
  172. }
  173. .menu__item::after {
  174. left: 0;
  175. bottom: 0 ;
  176. content: " " ;
  177. height: 0.25em ;
  178. position: absolute ;
  179. border-radius: 2em ;
  180. transform-origin: left center ;
  181. background-color: currentColor ;
  182. width: calc( var(--lineWidth) + 5px ) ;
  183. transform: translate3d(3em , 0, 0) scaleX(0) ;
  184. transition: transform calc( var(--duration) + .2s) var(--cubic) ;
  185. }
  186. .menu__text {
  187. left: 4.15em ;
  188. font-size: 1.5em ;
  189. position: absolute ;
  190. text-transform: capitalize ;
  191. letter-spacing: .01em ;
  192. transform: translate3d(0, 109%, 0) ;
  193. transition: transform calc( var(--duration) / 3.7 ) ;
  194. }
  195. .menu__item.active {
  196. flex-grow: 2.7 ;
  197. color: var(--color-2) ;
  198. }
  199. .menu__item.active .menu__icon {
  200. transform: translate3d(-95% , 0, 0) ;
  201. }
  202. .menu__item.active::before {
  203. transform: scale(1) ;
  204. }
  205. .menu__item.active::after {
  206. transform: translate3d(6.3em , 0, 0) scaleX(1) ;
  207. transition: transform var(--duration) var(--cubic) ;
  208. }
  209. .menu__text.active {
  210. transform: translate3d(0 , 0, 0) ;
  211. transition: transform calc(var(--duration) / 1.5) ;
  212. }
  213. .icon {
  214. --duration-icon: 1s ;
  215. fill: none ;
  216. width: 2.5em ;
  217. height: 2.5em ;
  218. display: block ;
  219. stroke-width: 15 ;
  220. stroke-miterlimit: 10 ;
  221. }
  222. .active #home-anm {
  223. animation: home var(--duration-icon) ;
  224. }
  225. @keyframes home {
  226. 25% {
  227. transform: translate3d(0, -.8em , 0) ;
  228. }
  229. 50% {
  230. transform: translate3d(0, .5em , 0) ;
  231. }
  232. }
  233. #strategy-anm {
  234. transform: scaleX(.85) ;
  235. transform-origin: center ;
  236. }
  237. .active #strategy-anm {
  238. animation: strategy var(--duration-icon) ;
  239. }
  240. @keyframes strategy {
  241. 50% {
  242. transform: scaleX(1) ;
  243. }
  244. 100%{
  245. transform: scaleX(.85) ;
  246. }
  247. }
  248. .active #strategy-cir1 {
  249. animation: strategy-cir1 var(--duration-icon);
  250. }
  251. .active #strategy-cir2 {
  252. animation: strategy-cir2 var(--duration-icon) .1s;
  253. }
  254. .active #strategy-cir3 {
  255. animation: strategy-cir3 var(--duration-icon) .2s;
  256. }
  257. @keyframes strategy-cir1 {
  258. 50% {
  259. transform: translate3d(-.7em,-0.7em,0);
  260. }
  261. 100%{
  262. transform: translate3d(0,0,0);
  263. }
  264. }
  265. @keyframes strategy-cir2 {
  266. 35% {
  267. transform: translate3d(0,-0.7em,0);
  268. }
  269. 100%{
  270. transform: translate3d(0,0,0);
  271. }
  272. }
  273. @keyframes strategy-cir3 {
  274. 35% {
  275. transform: translate3d(.7em,-0.7em,0);
  276. }
  277. 100%{
  278. transform: translate3d(0,0,0);
  279. }
  280. }
  281. .active #period-anm {
  282. transform-origin: center 100% ;
  283. animation: period var(--duration-icon) ;
  284. }
  285. .active #period-cir {
  286. transform-origin: center ;
  287. animation: period-cir var(--duration-icon) ;
  288. }
  289. .active #period-line {
  290. stroke-dasharray: 66 ;
  291. animation: period-line calc( var(--duration-icon) / 2.5 ) reverse ;
  292. }
  293. @keyframes period {
  294. 35% {
  295. transform: scaleY(.85) ;
  296. }
  297. 60% , 70% {
  298. transform: scaleY(1.2) ;
  299. }
  300. 100% {
  301. transform: scaleY(1) ;
  302. }
  303. }
  304. @keyframes period-cir {
  305. 0%{
  306. opacity: 0 ;
  307. }
  308. 35% {
  309. opacity: 1 ;
  310. transform: translate3d(15%, -55%, 0) ;
  311. }
  312. 60%{
  313. opacity: 0 ;
  314. transform: translate3d(-8%, -50%, 0) ;
  315. }
  316. }
  317. @keyframes period-line {
  318. 100% {
  319. stroke-dashoffset: 66 ;
  320. }
  321. }
  322. .active #security-cir {
  323. transform-box: fill-box ;
  324. transform-origin: center ;
  325. animation: security-cir calc( var(--duration-icon) / 1.5 ) ;
  326. }
  327. @keyframes security-cir {
  328. 0% {
  329. transform: scale(0) ;
  330. }
  331. 100% {
  332. transform: scale(1) ;
  333. }
  334. }
  335. .active #security-strok {
  336. stroke-dasharray: 96;
  337. animation: security-strok calc( var(--duration-icon) / 1.2 ) ;
  338. }
  339. @keyframes security-strok {
  340. 0% {
  341. stroke-dashoffset: 60 ;
  342. }
  343. 100% {
  344. stroke-dashoffset: 230 ;
  345. }
  346. }
  347. .active #settings-anm {
  348. transform-box: fill-box ;
  349. transform-origin: center ;
  350. animation: settings-anm calc( var(--duration-icon) / 1.5 ) ;
  351. }
  352. @keyframes settings-anm {
  353. 0% {
  354. transform: rotate(-60deg);
  355. }
  356. 50% {
  357. transform: rotate(60deg);
  358. }
  359. }
  360. js
  361. // Designed by: Hoang Nguyen
  362. // Original image: https://dribbble.com/shots/5919154-Tab-Bar-Label-Micro-Interaction
  363. const buttons = document.querySelectorAll(".menu__item");
  364. let activeButton = document.querySelector(".menu__item.active");
  365. buttons.forEach(item => {
  366. const text = item.querySelector(".menu__text");
  367. setLineWidth(text, item);
  368. window.addEventListener("resize", () => {
  369. setLineWidth(text, item);
  370. })
  371. item.addEventListener("click", function() {
  372. if (this.classList.contains("active")) return;
  373. this.classList.add("active");
  374. if (activeButton) {
  375. activeButton.classList.remove("active");
  376. activeButton.querySelector(".menu__text").classList.remove("active");
  377. }
  378. handleTransition(this, text);
  379. activeButton = this;
  380. });
  381. });
  382. function setLineWidth(text, item) {
  383. const lineWidth = text.offsetWidth + "px";
  384. item.style.setProperty("--lineWidth", lineWidth);
  385. }
  386. function handleTransition(item, text) {
  387. item.addEventListener("transitionend", (e) => {
  388. if (e.propertyName != "flex-grow" ||
  389. !item.classList.contains("active")) return;
  390. text.classList.add("active");
  391. });
  392. }

内容仅供参考

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/96987
推荐阅读
相关标签
  

闽ICP备14008679号