*新闻详情页*/>
1直以来,应用纯 CSS 完成波浪纹实际效果全是10分艰难的。
由于完成波浪纹的曲线图必须依靠贝塞尔曲线图。
而应用纯 CSS 的方法,完成贝塞尔曲线图,额,临时是沒有很好的方式。
自然,依靠别的能量(SVG、CANVAS),是能够很轻轻松松的进行所谓的波浪纹实际效果的。
下面先看来看非 CSS 方法完成的波浪纹实际效果
SVG 完成波浪纹实际效果
依靠 SVG ,是很非常容易画出3次贝塞尔曲线图的。
<svg width="200px" height="200px" version="1.1" xmlns="http://www.w3.org/2000/svg"> <text class="liquidFillGaugeText" text-anchor="middle" font-size="42px" transform="translate(100,120)" style="fill: #000">50.0%</text> <!-- Wave --> <g id="wave"> <path id="wave⑵" fill="rgba(154, 205, 50, .8)" d="M 0 100 C 133.633 85.12 51.54 116.327 200 100 A 95 95 0 0 1 0 100 Z"> <animate dur="5s" repeatCount="indefinite" attributeName="d" attributeType="XML" values="M0 100 C90 28, 92 179, 200 100 A95 95 0 0 1 0 100 Z; M0 100 C145 100, 41 100, 200 100 A95 95 0 0 1 0 100 Z; M0 100 C90 28, 92 179, 200 100 A95 95 0 0 1 0 100 Z"></animate> </path> </g> <circle cx="100" cy="100" r="80" stroke-width="10" stroke="white" fill="transparent"></circle> <circle cx="100" cy="100" r="90" stroke-width="20" stroke="yellowgreen" fill="none" class="percentage-pie-svg"></circle> </svg>
画出3次贝塞尔曲线图的关键在于 <path id="wave⑵" fill="rgba(154, 205, 50, .8)" d="M 0 100 C 133.633 85.12 51.54 116.327 200 100 A 95 95 0 0 1 0 100 Z">这1段。感兴趣爱好的能够自主去科学研究科学研究
canvas 完成波浪纹实际效果
应用 canvas 完成波浪纹实际效果的基本原理与 SVG 1样,全是运用相对路径绘图出3次贝塞尔曲线图并授予动漫实际效果。
$(function() { let canvas = $("canvas"); let ctx = canvas[0].getContext('2d'); let radians = (Math.PI / 180) * 180; let startTime = Date.now(); let time = 2000; let clockwise = 1; let cp1x, cp1y, cp2x, cp2y; // 原始情况 // ctx.bezierCurveTo(90, 28, 92, 179, 200, 100); // 结尾情况 // ctx.bezierCurveTo(145, 100, 41, 100, 200, 100); requestAnimationFrame(function waveDraw() { let t = Math.min(1.0, (Date.now() - startTime) / time); if(clockwise) { cp1x = 90 + (55 * t); cp1y = 28 + (72 * t); cp2x = 92 - (51 * t); cp2y = 179 - (79 * t); } else { cp1x = 145 - (55 * t); cp1y = 100 - (72 * t); cp2x = 41 + (51 * t); cp2y = 100 + (79 * t); } ctx.clearRect(0, 0, 200, 200); ctx.beginPath(); ctx.moveTo(0, 100); // 绘图3次贝塞尔曲线图 ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, 200, 100); // 绘图圆弧 ctx.arc(100, 100, 100, 0, radians, 0); ctx.fillStyle = "rgba(154, 205, 50, .8)"; ctx.fill(); ctx.save(); if( t == 1 ) { startTime = Date.now(); clockwise = !clockwise; } requestAnimationFrame(waveDraw); }); })
关键是运用了动态性绘图 ctx.bezierCurveTo() 3次贝塞尔曲线图完成波浪纹的健身运动实际效果,感兴趣爱好的能够自主科学研究。
CSS完成波浪纹实际效果
最初并不是说css不可以完成吗?是,大家沒有方法立即绘图出3次贝塞尔曲线图,可是大家能够运用1些讨巧的方式,仿真模拟做到波浪纹健身运动时的实际效果,下面看来看这类方式。
基本原理
基本原理10分简易,大家都了解,1个正方形,给它加上 border-radius: 50%,可能获得1个圆形。
width: 240px; height: 240px; background: #f13f84; border-radius: 50%;
好的,假如 border-radius 没到 50%,可是贴近 50% ,大家会获得1个这样的图型(留意边角,全部图型给人的觉得是有点圆,却并不是很圆。)
width: 240px; height: 240px; background: #f13f84; border-radius: 40%;
好的,那整这么个图型又有甚么用?还能变出波浪纹来不了?
大家让上面这个图型翻转起来(rotate) ,看看实际效果:
CSS完成波浪纹实际效果
@keyframes rotate{ from{transform: rotate(0deg)} to{transform: rotate(359deg)} } .ripple{ width: 240px; height: 240px; background: #f13f84; border-radius: 40%; animation: rotate 3s linear infinite; }
将会许多人看到这里还没懂转动起来的用意,细心盯着1边看,是会有相近波浪纹的波动实际效果的。
而大家的目地,便是要依靠这个动态性转换的波动动漫,仿真模拟生产制造出相近波浪纹的实际效果。
完成
自然,这里看到是全景图完成图,因此觉得其实不显著,OK,让大家用1个个事例看看实际完成起来能做到甚么样的实际效果。
大家运用上面基本原理能够保证的1种波浪纹健身运动情况实际效果图:
后边漂浮的波浪纹实际效果,实际上便是运用了上面的 border-radius: 40% 的椭圆型,只是变大了许多倍,视线以外的图型都 是掩藏的 ,只留下了1条边的视线,而且提升了1些相应的transform 转换。
将会有一部分同学,还存在疑惑,OK,那大家把上面的实际效果掩藏一部分显示信息解决,将视线以外的动漫也补齐,那末实际上转化成波浪纹的基本原理是这样的:
图中的鲜红色框便是大家具体的视线范畴。
值得留意的是,要看到,这里大家转化成波浪纹,其实不是运用转动的椭圆自身,而是运用它去激光切割情况,造成波浪纹的实际效果。
以上便是本文的所有內容,期待对大伙儿的学习培训有一定的协助,也期待大伙儿多多适用脚本制作之家。
Copyright © 2002-2020 小程序开发者工具_小程序在线生成平台_小程序编辑_免费的小程序_微信小程序在哪里 版权所有 (网站地图) 粤ICP备10235580号