Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
* { box-sizing: border-box; padding: 0; margin: 0; } body { min-height: 100vh; background: #403c3c; /* center in the viewport */ display: grid; justify-content: center; align-content: center; } /* on the svg element set up a default value for the --stroke-dash and --stroke-dash-negative attributes 46 roughly being the length of the longest path.air */ body > svg { width: 600px; height: auto; --stroke-dash: 46; --stroke-dash-negative: -46; } /* animate the car to move slightly forwards and backwards */ g#car { transform: translateX(-3px); animation: translate 2s ease-in-out infinite; } /* animate the shadow to skew toward the left */ path#shadow { animation: skew 2s ease-in-out infinite; } /* animate the wheels to spin clockwise*/ g.wheels use { animation: rotate 2s linear infinite; } /* animate the dashes of air to briefly show them and then hide them from view */ path.air { /* starting from the values described by the --stroke-dash property ! the property is updated for each path in the script */ stroke-dasharray: var(--stroke-dash); stroke-dashoffset: var(--stroke-dash); /* ! the delay of the animation is also set up in the script */ animation: offset 2s linear infinite; /* opacity to hide the obnoxious dots otherwise shown on firefox and edge */ opacity: 0; } /* keyframe animations ! be sure to have the animations overlap as to show a realistic behavior - as the car moves right the wheels spin faster, the shadow skews left, the dashes of air appear in sequence - as the car moves left the wheels spin slower while the shadow returns to its resting place */ @keyframes translate { 50% { transform: translateX(3px); } 100% { transform: translateX(-3px); } } @keyframes skew { 50% { transform: skewX(-20deg); } } @keyframes rotate { 50% { transform: rotate(4turn); } 100% { transform: rotate(6turn); } } /* beside animating the stroke-dashoffset property rapidly change the opacity to show the dashes and hide them when they are removed by changing the offset property otherwise the dashes would still be partially visible on firefox and edge (at least) */ @keyframes offset { 1% { opacity: 1; } 15% { stroke-dashoffset: 0; opacity: 1; } 24% { opacity: 1; } 25% { opacity: 0; /* ! on chrome and firefox the calc() function allows to compute the negative value, but Edge seems to prefer having another variable instead */ /* stroke-dashoffset: calc(var(--stroke-dash) * -1px); */ stroke-dashoffset: var(--stroke-dash-negative); } 100% { stroke-dashoffset: var(--stroke-dash-negative); } }
JavaScript
// target all path elements describing the gusts of air around the race car const paths = document.querySelectorAll('path.air'); /* for each path update the --stroke-dash property to match the length of the stroke ! create another property for the negative offset (mostly due to Edge not liking the calc() function with custom properties) ! include also an increasing delay to animate the path in sequence */ // add an increasing delay to the animation paths.forEach((path, index) => { const totalLength = path.getTotalLength(); path.style.setProperty('--stroke-dash', totalLength); path.style.setProperty('--stroke-dash-negative', -totalLength); // ! as the first path actually describes a stroke on the left side of the car, tailor its delay to occur with the dashes on the left side if (index === 0) { path.style.animationDelay = `${0.08 * (paths.length - 2)}s`; } else { path.style.animationDelay = `${0.08 * index}s`; } });
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>svg赛车加载动画-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号