问题描述

CSS animation没办法解决SVG路径运动的问题,下图路径运动的过程,通过查资料发现所有的IE的版本都不支持SVG animation。在IE中没有水流动的效果。

主要代码

<style>
svg #water_path {
stroke-dasharray: 53, 200;
stroke-dashoffset: -180;
-webkit-animation: water 30s linear infinite;
-moz-animation: water 30s linear infinite;
-ms-animation: water 30s linear infinite;
-o-animation: water 30s linear infinite;
animation: water 30s linear infinite; } @keyframes water {
0% { stroke-dashoffset: -200;
}
100% { stroke-dashoffset: 1000;
}
}
@-ms-keyframes water {
0% { stroke-dashoffset: -200;
}
100% { stroke-dashoffset: 1000;
}
}
@-moz-keyframes water {
100% { stroke-dashoffset: 1000;
}
} @-webkit-keyframes water {
100% { stroke-dashoffset: 1000;
}
} @-o-keyframes water {
100% { stroke-dashoffset: 1000;
}
} </style>
<script type="text/javascript">
var element = document.getElementById("animpath");
var pathLength = element.getTotalLength();
element.style.strokeDashoffset = pathLength;
function animateRoute(e, len) { len += 1;//每次偏移的位置
if (len >= 1000) {
//大于1000后重置初始偏移,重复运动
len = -200;
}
//设置元素偏移
element.style.strokeDashoffset = len;
//10毫秒执行一次
setTimeout(function () {
animateRoute(e, len);
}, 10); }
animateRoute(element, pathLength);
</script>
<div class="svg-warp" style="background-color: #001020;height: 100%">
<svg class="home-svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 800">
<path class="animate" id="animpath" fill="none" stroke="#F6B457" stroke-width="6"
stroke-dasharray="53, 200" stroke-linecap="round" d="
M595.87,381.5c3.75,75.25-102.441,73.5-104.667,8.917l0.097-16.092"/>
</svg>
</div>

stroke-miterlimi 不可以添加。stroke-width="6"的值要小于等于6.从网上查资料,有案例是大于6也可以运行,感觉可能是简单路径的原因,具体原因不是很清楚,效果代码如下,测试在IE中显示效果受到很多条件的限制,但是基本上可以运动起来了。案例代码

完整效果

涉及到TweenMax制作动画,后续把完整代码整理上传,先看下效果图

总结

写东西的时候总是想着要对读者负责,但是知识有限,能完成并写出来希望能跟大家一起学习进步,有错希望能得到指点,喜欢希望能收到点赞。

更新

在开发过程中发现var pathLength = element.getTotalLength();
只能应用于path路径
这里还有另外一种实现方法,应用于path line 等
案例代码

本文转载于:猿2048➦https://www.mk2048.com/blog/blog.php?id=haic2i00b2j

最新文章

  1. 配置hadoop
  2. 弄个知乎的粒子动态背景_实践particles.js
  3. linux下截取整个网页
  4. BZOJ3226: [Sdoi2008]校门外的区间
  5. abstract的method是否可同时是static,是否可同时是native,是否可同时是synchronized?
  6. Powershell 快捷键
  7. x01.Weiqi.13: 鼎力推荐
  8. SQL Server 2000服务器安装剖析
  9. com.alibaba的fastjson简介
  10. vscode下调试运行c++
  11. Eclipse Java EE IDE for Web Developers集成的Maven 3 指向自己安装的 Maven
  12. ubuntu安装命令
  13. shell_语法
  14. 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem B. Travelling Camera Problem set贪心
  15. 《转载》Linux服务之搭建FTP服务器&amp;&amp;分布式文件服务器的比较
  16. C++并发编程 02 数据共享
  17. Python3.5 学习八
  18. 39、请用代码简答实现stack
  19. lzma解压
  20. because of an existing model object of the same name

热门文章

  1. 深入Mybatis框架
  2. LeetCode-096-不同的二叉搜索树
  3. xor加密的python实现
  4. laravel7 h-ui模板点改
  5. laravel7 数据迁移及填充数据
  6. php 23种设计模型 - 建造者模式
  7. 用两行代码实现重试功能,spring-retry真是简单而优雅
  8. springcloud报错-Ribbon整合Eureka,出现 No instances available for XXX 异常
  9. Windows10 1809版本Windows自动更新服务无法禁用问题解决方案
  10. SQL注入及防止SQL注入