1 Star 3 Fork 0

张鑫旭/css-offset-polyfill

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

css-offset-polyfill

介绍

Polyfill CSS offset-path属性中的circle()、ellipse()、inset()、polygon()函数。

实现原理

借助CSS自定义属性让浏览器无法识别的语法也能够正常保留,这样就能够对这些不支持的语法进行解析与支持。

详细原理参见这里:https://www.zhangxinxu.com/wordpress/?p=9537

使用示意

  1. 引入JS,例如:
<script src="./offset-path.js"></script>
  1. 需要使用offset-path其他函数语法的元素新增一个自定义属性is-offset-path,例如:
<img src="horse.png" class="horse-run" is-offset-path>
  1. 使用CSS自定义属性设置相关的运动路径函数,例如这里使用外部的SVG元素路径:
.horse-run {
 --offset-path: url(#road);
 offset-path: var(--offset-path);
 animation: motion 3s linear infinite;
}

页面中的SVG元素代码如下:

<svg width="280" height="150" viewBox="0 0 280 150">
 <path id="road" d="M10,80 q100,120 120,20 q140,-50 160,0"/>
</svg>
  1. 效果自动完成,此时,offset-path.js会把url(#road)转换成浏览器可以识别的path()函数,于是就有了对应的运动效果。

更多案例

此demo页面包含其他offse-path属性函数的Polyfill效果示意:https://www.zhangxinxu.com/study/202008/offset-path-polyfill.php

许可证

MIT

MIT License Copyright (c) 2020 张鑫旭 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Polyfill CSS offset-path属性中的circle()、ellipse()、inset()、polygon()函数。 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/zhangxinxu/css-offset-polyfill.git
git@gitee.com:zhangxinxu/css-offset-polyfill.git
zhangxinxu
css-offset-polyfill
css-offset-polyfill
master

搜索帮助

Cb406eda 1850385 E526c682 1850385