html - 虚线 SVG 动画
问题描述
我对使用 SVG 动画比较陌生,所以如果有一个简单的答案,我提前道歉。通过结合使用 Scrollmajic.js 和 GASP,我能够在用户滚动到特定位置时让 SVG 动画化。我遇到的问题是动画将它从虚线转换为实线。我做了一些研究,发现使用面具是实现这一目标的最佳方法,尽管我对如何使用这种方法有点迷茫。
https://codepen.io/ncanarelli/pen/wvaeLNa
js:
$(document).ready(function() {
function pathPrepare ($el) {
var lineLength = $el[0].getTotalLength();
$el.css("stroke-dasharray", lineLength);
$el.css("stroke-dashoffset", lineLength);
}
// init controller
var controller = new ScrollMagic.Controller();
// loop through all elements
$(".svg-animation").each(function() {
var $thePath = $(this).find("path#thePath");
// prepare SVG
pathPrepare($thePath);
// build tween
var tween = new TimelineMax()
.add(TweenMax.to($thePath, 1, {
strokeDashoffset: 0,
ease:Linear.easeNone
}))
// build scene
var scene = new ScrollMagic.Scene({
triggerElement: $(this)[0],
duration: 200,
tweenChanges: true,
reverse: true
})
.setTween(tween)
.addTo(controller)
.addIndicators();
});
});
更新:更新 .js 以反映 .each 循环 + 其他修改。仍然有实施面具的问题。
解决方案
推荐阅读
- prestashop - 调用函数自 product-variants.tpl Prestashop
- python - CNN OCR 机器可读区
- oracle - 四分位数百分比分析
- angular - Angular 使用 Jhipster,如何添加或捆绑外部 js 文件?
- rxjs - rxjs concatMap 与数组
- pdf-generation - Drupal 8 和打印机、电子邮件和 PDF - 找不到页面
- react-native - 使用 composeWithDevTools() 时是否应将 Redux Devtools Extension 作为开发依赖项安装?
- php - 该行在 MySQL 中没有被删除,PHP 没有返回错误
- jira - Jira API 创建工作日志返回 HTTP 201,但记录的票证不在 JIRA(网络应用程序)内
- react-redux - 为什么当 redux 存储更改时我的 React 视图没有更新?