百款拿来就能用的网页特效,不来看看吗?

写在前面:

我特别喜欢收集前端好看的特效代码,前端好用的网站。今天给大家分享出来,如果觉得有帮助可以点赞收藏支持一下,如果能关注一下就再好不过了ヾ(≧▽≦*)o,之后还会分享许多干货,话不多说,上动图:

目录

🍓1.动态菜单

🍇2.会动的龙卷风

🍒3.围绕太阳转圈圈

🍊4.更多动态特效


非新手可以跳过

考虑到看此文章的小伙伴有一些是新手。

先来一个简介

前端是创建Web页面或app等前端界面呈现给用户的过程,通过HTML,CSS及JavaScript以及衍生出来的各种技术、框架、解决方案,来实现互联网产品的用户界面交互。它从网页制作演变而来,名称上有很明显的时代特征。在互联网的演化进程中,网页制作是Web1.0时代的产物,早期网站主要内容都是静态,以图片和文字为主,用户使用网站的行为也以浏览为主。随着互联网技术的发展和HTML5、CSS3的应用,现代网页更加美观,交互效果显著,功能更加强大。
 

有些小伙伴0基础小伙伴担心,我没有编程工具怎么办?

可以参照这篇文章:http://t.csdn.cn/fB8yF

如果小伙伴想一起来学习前端知识,那么就从这篇文章开始吧

前端HTML:

http://t.csdn.cn/aQR2k

🍓1.动态菜单

 把此菜单特效放到网站上是不是很炫酷,快来行动吧!

HTML代码:


   
   
  1. <input class="menu-checkbox" id="menu" type="checkbox" name="menu" />
  2. <nav class="menu">
  3. <label class="menu-dots" for="menu">
  4. <span class="menu-dot"> </span>
  5. <span class="menu-dot"> </span>
  6. <span class="menu-dot"> </span>
  7. </label>
  8. <ul class="menu-items">
  9. <li class="menu-item">
  10. <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
  11. <path d="M9.25 8C9.25 9.24264 8.24264 10.25 7 10.25C5.75736 10.25 4.75 9.24264 4.75 8C4.75 6.75736 5.75736 5.75 7 5.75C8.24264 5.75 9.25 6.75736 9.25 8Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"> </path>
  12. <path d="M9.25 16C9.25 17.2426 8.24264 18.25 7 18.25C5.75736 18.25 4.75 17.2426 4.75 16C4.75 14.7574 5.75736 13.75 7 13.75C8.24264 13.75 9.25 14.7574 9.25 16Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"> </path>
  13. <path d="M9 15L19.25 6.75" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"> </path>
  14. <path d="M9 9L19.25 16.25" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"> </path>
  15. </svg>
  16. </li>
  17. <li class="menu-item">
  18. <svg width="24" height="24" fill="none" viewBox="0 0 24 24">
  19. <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M6.5 15.25V15.25C5.5335 15.25 4.75 14.4665 4.75 13.5V6.75C4.75 5.64543 5.64543 4.75 6.75 4.75H13.5C14.4665 4.75 15.25 5.5335 15.25 6.5V6.5"> </path>
  20. <rect width="10.5" height="10.5" x="8.75" y="8.75" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" rx="2"> </rect>
  21. </svg>
  22. </li>
  23. <li class="menu-item">
  24. <svg width="24" height="24" fill="none" viewBox="0 0 24 24">
  25. <path stroke="currentColor" stroke-width="1.5" d="M19.25 10C19.25 12.7289 17.85 15.25 16.5 15.25C15.15 15.25 13.75 12.7289 13.75 10C13.75 7.27106 15.15 4.75 16.5 4.75C17.85 4.75 19.25 7.27106 19.25 10Z"> </path>
  26. <path stroke="currentColor" stroke-width="1.5" d="M16.5 15.25C16.5 15.25 8 13.5 7 13.25C6 13 4.75 11.6893 4.75 10C4.75 8.31066 6 7 7 6.75C8 6.5 16.5 4.75 16.5 4.75"> </path>
  27. <path stroke="currentColor" stroke-width="1.5" d="M6.75 13.5V17.25C6.75 18.3546 7.64543 19.25 8.75 19.25H9.25C10.3546 19.25 11.25 18.3546 11.25 17.25V14.5"> </path>
  28. </svg>
  29. </li>
  30. <li class="menu-item">
  31. <svg width="24" height="24" fill="none" viewBox="0 0 24 24">
  32. <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M5.75 11.75C5.75 11.1977 6.19772 10.75 6.75 10.75H17.25C17.8023 10.75 18.25 11.1977 18.25 11.75V17.25C18.25 18.3546 17.3546 19.25 16.25 19.25H7.75C6.64543 19.25 5.75 18.3546 5.75 17.25V11.75Z"> </path>
  33. <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M7.75 10.5V9.84343C7.75 8.61493 7.70093 7.29883 8.42416 6.30578C8.99862 5.51699 10.0568 4.75 12 4.75C14 4.75 15.25 6.25 15.25 6.25"> </path>
  34. </svg>
  35. </li>
  36. <li class="menu-item">
  37. <svg width="24" height="24" fill="none" viewBox="0 0 24 24">
  38. <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M19.25 19.25L15.5 15.5M4.75 11C4.75 7.54822 7.54822 4.75 11 4.75C14.4518 4.75 17.25 7.54822 17.25 11C17.25 14.4518 14.4518 17.25 11 17.25C7.54822 17.25 4.75 14.4518 4.75 11Z"> </path>
  39. </svg>
  40. </li>
  41. <li class="menu-item">
  42. <svg width="24" height="24" fill="none" viewBox="0 0 24 24">
  43. <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M7.75 7.75H19.25L17.6128 14.7081C17.4002 15.6115 16.5941 16.25 15.666 16.25H11.5395C10.632 16.25 9.83827 15.639 9.60606 14.7618L7.75 7.75ZM7.75 7.75L7 4.75H4.75"> </path>
  44. <circle cx="10" cy="19" r="1" fill="currentColor"> </circle>
  45. <circle cx="17" cy="19" r="1" fill="currentColor"> </circle>
  46. </svg>
  47. </li>
  48. </ul>
  49. <label for="menu" class="menu-closer-overlay"> </label>
  50. </nav>

CSS代码:


   
   
  1. body {
  2. height: 100vh;
  3. display: flex;
  4. flex-direction: column;
  5. align-items: center;
  6. justify-content: center;
  7. background: linear-gradient(to left, #2bc0e4, #eaecc6);
  8. }
  9. .menu-checkbox {
  10. display: none;
  11. }
  12. .menu {
  13. position: relative;
  14. }
  15. .menu-dots {
  16. width: 5rem;
  17. height: 5rem;
  18. border-radius: 50%;
  19. box-shadow: 0 0 0 0.3rem #161e3f;
  20. display: flex;
  21. flex-direction: column;
  22. align-items: center;
  23. justify-content: center;
  24. transform: rotate(90deg);
  25. transition: 0.3s;
  26. cursor: pointer;
  27. }
  28. .menu-dots:hover {
  29. box-shadow: 0 0 0 0.3rem #161e3f, 0 0 0 1rem rgba(#161e3f, 0.16);
  30. transform: scale(1.2) rotate(90deg);
  31. }
  32. .menu-dot {
  33. width: 0.45rem;
  34. height: 0.45rem;
  35. background-color: #161e3f;
  36. border-radius: 50%;
  37. }
  38. .menu-dot + .menu-dot {
  39. margin-top: 0.3rem;
  40. }
  41. .menu-items {
  42. position: absolute;
  43. top: -2.3rem;
  44. left: -2.2rem;
  45. width: 9.4rem;
  46. height: 11rem;
  47. color: #fff;
  48. pointer-events: none;
  49. display: grid;
  50. grid-template-columns: 1fr 1fr;
  51. opacity: 0;
  52. transition: 0.3s;
  53. }
  54. .menu-item {
  55. transform: scale(0.5);
  56. filter: blur(10px);
  57. transition: 0.3s;
  58. }
  59. .menu-item:nth-child(odd) {
  60. text-align: right;
  61. }
  62. .menu-item:nth-child(even) {
  63. text-align: left;
  64. }
  65. .menu-item:first-child,
  66. .menu-item:last-child {
  67. grid-column: span 2;
  68. text-align: center;
  69. }
  70. .menu-checkbox:checked + .menu > .menu-dots {
  71. transform: none;
  72. box-shadow: 0 0 0 3.4rem #161e3f;
  73. }
  74. .menu-checkbox:checked + .menu > .menu-items {
  75. opacity: 1;
  76. pointer-events: auto;
  77. }
  78. .menu-closer-overlay {
  79. position: absolute;
  80. left: 0;
  81. top: 0;
  82. width: 100%;
  83. height: 100%;
  84. background-color: transparent;
  85. border-radius: 50%;
  86. z-index: 2;
  87. pointer-events: none;
  88. }
  89. .menu-checkbox:checked + .menu > .menu-items > .menu-item {
  90. opacity: 1;
  91. transform: none;
  92. filter: none;
  93. }
  94. .menu-checkbox:checked + .menu > .menu-items > .menu-item:nth-child(1) {
  95. transition-delay: 0.05s;
  96. }
  97. .menu-checkbox:checked + .menu > .menu-items > .menu-item:nth-child(2) {
  98. transition-delay: 0.1s;
  99. }
  100. .menu-checkbox:checked + .menu > .menu-items > .menu-item:nth-child(3) {
  101. transition-delay: 0.15s;
  102. }
  103. .menu-checkbox:checked + .menu > .menu-items > .menu-item:nth-child(4) {
  104. transition-delay: 0.2s;
  105. }
  106. .menu-checkbox:checked + .menu > .menu-items > .menu-item:nth-child(5) {
  107. transition-delay: 0.25s;
  108. }
  109. .menu-checkbox:checked + .menu > .menu-items > .menu-item:nth-child(6) {
  110. transition-delay: 0.3s;
  111. }
  112. .menu-checkbox:checked + .menu > .menu-closer-overlay {
  113. pointer-events: auto;
  114. cursor: pointer;
  115. }

🍇2.会动的龙卷风

 JS:


   
   
  1. import * as THREE from "https://cdn.skypack.dev/three@0.133.1/build/three.module";
  2. import { GUI } from "https://cdn.skypack.dev/lil-gui@0.16.1";
  3. const container = document. querySelector( '.container');
  4. const config = {
  5. height: 1.1,
  6. density: 2.5,
  7. curl: 12,
  8. };
  9. class Controls {
  10. constructor( ) {
  11. const gui = new GUI();
  12. if ( window. innerWidth < 600) gui. close();
  13. gui. add(config, 'height', 1, 1.8). step( .01). onChange( v => {
  14. viz. material. uniforms. u_height. value = v;
  15. });
  16. gui. add(config, 'density', 1, 4). step( .1). onChange( v => {
  17. viz. material. uniforms. u_density. value = v;
  18. });
  19. gui. add(config, 'curl', 4, 20). step( .1). onChange( v => {
  20. viz. material. uniforms. u_curl. value = v;
  21. });
  22. }
  23. }
  24. class Viz {
  25. constructor( ) {
  26. this. renderer = new THREE. WebGLRenderer({ antialias: true, alpha: true });
  27. container. appendChild( this. renderer. domElement);
  28. this. scene = new THREE. Scene();
  29. this. camera = new THREE. PerspectiveCamera( 45, window. innerWidth / window. innerHeight, 1, 1000);
  30. this. camera. position. z = 2.9;
  31. this. camera. position. y = 1.1;
  32. this. camera. lookAt( 0, 0, 0);
  33. this. rotationY = - .4 * Math. PI;
  34. this. raycaster = new THREE. Raycaster();
  35. this. mouse = new THREE. Vector2( 0, 0);
  36. this. mouseTarget = new THREE. Vector2( 0, 0);
  37. this. clock = new THREE. Clock();
  38. this. setupScene();
  39. this. render();
  40. }
  41. setupScene( ) {
  42. const planeMaterial = new THREE. MeshBasicMaterial({
  43. color: 0xffffff
  44. });
  45. const planeGeometry = new THREE. PlaneGeometry( 2000, 1000);
  46. this. floor = new THREE. Mesh(planeGeometry, planeMaterial);
  47. this. floor. position. set( 0, - 2, 0);
  48. this. floor. rotation. set(- .2 * Math. PI, 0, 0);
  49. this. scene. add( this. floor);
  50. this. material = new THREE. ShaderMaterial({
  51. uniforms: {
  52. u_time: { type: 'f', value: 0 },
  53. u_height: { type: 'f', value: config. height },
  54. u_density: { type: 'f', value: config. density },
  55. u_curl: { type: 'f', value: config. curl },
  56. u_wind: { type: 'v2', value: new THREE. Vector2( 0, 0) },
  57. },
  58. vertexShader: document. getElementById( "vertexShader"). textContent,
  59. fragmentShader: document. getElementById( "fragmentShader"). textContent,
  60. side: THREE. DoubleSide,
  61. transparent: true
  62. });
  63. const curve = new THREE. LineCurve3(
  64. new THREE. Vector3( 0, 0, 0),
  65. new THREE. Vector3( 0, 1, 0),
  66. );
  67. const geometry = new THREE. TubeGeometry(curve, 512, .55, 512, false);
  68. this. mesh = new THREE. Mesh(geometry, this. material);
  69. this. mesh. position. set( 0, - .65, 0);
  70. this. mesh. rotation. set( 0, this. rotationY, 0);
  71. this. scene. add( this. mesh);
  72. }
  73. addCanvasEvents( ) {
  74. container. addEventListener( 'mousemove', (e) => {
  75. updateMousePosition(e. clientX, e. clientY, this);
  76. });
  77. container. addEventListener( 'touchmove', (e) => {
  78. updateMousePosition(e. touches[ 0]. pageX, e. touches[ 0]. pageY, this);
  79. });
  80. function updateMousePosition( eX, eY, viz) {
  81. const x = eX - container. offsetLeft;
  82. const y = eY - container. offsetTop;
  83. viz. mouseTarget. x = x / container. offsetWidth * 2 - 1;
  84. viz. mouseTarget. y = -(y / container. offsetHeight) * 2 + 1;
  85. }
  86. }
  87. render( ) {
  88. this. material. uniforms. u_time. value = 1.3 * this. clock. getElapsedTime();
  89. this. mouse. x += ( this. mouseTarget. x - this. mouse. x) * .1;
  90. this. mouse. y += ( this. mouseTarget. y - this. mouse. y) * .1;
  91. this. raycaster. setFromCamera( this. mouse, this. camera);
  92. const intersects = this. raycaster. intersectObject( this. floor);
  93. if (intersects. length) {
  94. this. material. uniforms. u_wind. value = new THREE. Vector2(intersects[ 0]. uv. x - .5, .5 - intersects[ 0]. uv. y)
  95. . rotateAround( new THREE. Vector2( 0, 0), this. rotationY)
  96. . multiplyScalar( 200);
  97. }
  98. this. renderer. render( this. scene, this. camera);
  99. }
  100. loop( ) {
  101. this. render();
  102. requestAnimationFrame( this. loop. bind( this));
  103. }
  104. updateSize( ) {
  105. this. camera. aspect = window. innerWidth / window. innerHeight;
  106. this. camera. updateProjectionMatrix();
  107. this. renderer. setSize( window. innerWidth, window. innerHeight);
  108. this. renderer. setPixelRatio( Math. min( window. devicePixelRatio, 2));
  109. }
  110. }
  111. const controls = new Controls();
  112. const viz = new Viz();
  113. viz. addCanvasEvents();
  114. viz. updateSize();
  115. viz. loop();
  116. window. addEventListener( 'resize', () => viz. updateSize());

需要完整代码,请滑倒本文最后面

🍒3.围绕太阳转圈圈

JS:


   
   
  1. gsap. registerPlugin( Draggable);
  2. const getDateFormat = ( date) => {
  3. return `${(date.getMonth() + 1).toString().padStart(2, "0")}-${date
  4. .getDate()
  5. .toString()
  6. .padStart(2, "0")}- ${date.getFullYear()}`;
  7. };
  8. const daysInYear = ( year) => {
  9. return (year % 4 === 0 && year % 100 > 0) || year % 400 == 0 ? 366 : 365;
  10. };
  11. document. querySelectorAll( ".useful-datepicker"). forEach( (datepicker) => {
  12. const input = datepicker. querySelector( "input");
  13. const today = new Date();
  14. input. value = getDateFormat(today);
  15. function updateDate( ) {
  16. gsap. set(datepicker. querySelector( ".earth"), {
  17. rotate: `${this.rotation * 3}deg`,
  18. });
  19. const percent = ( this. rotation / 360) * 100;
  20. const days = (percent / 100) * daysInYear(today. getFullYear());
  21. const newDate = new Date();
  22. newDate. setDate(today. getDate() + days);
  23. input. value = getDateFormat(newDate);
  24. }
  25. Draggable. create(datepicker. querySelector( ".rotate"), {
  26. type: "rotation",
  27. inertia: true,
  28. throwResistance: 0.5,
  29. onDrag: updateDate,
  30. onThrowUpdate: updateDate,
  31. });
  32. });

需要完整代码,请滑倒本文最后面

🍊4.更多动态特效

上面的3个特效都是来源于此网站,需要代码的小伙伴,可以访问此网站来获取代码。

并且里面有好多动态特效:CodePen: Online Code Editor and Front End Web Developer Community

网站介绍:

CodePen是一个面向前端设计师和开发人员的社会开发环境。构建和部署一个网站,展示你的工作,构建测试用例来学习和调试,并找到灵感。

构建、测试和发现前端代码的最佳场所

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值