【发布时间】:2016-01-21 01:08:30
【问题描述】:
我希望创建一个变量来保存在 jquery 中计算的 svg 圆长度。
$(function() {
$('svg').hover(function() {
/* Stuff to do when the mouse enters the element */
var pathLen = $(this).find('circle').getLengthOfPath????
$(this).find('circle')
.stop()
.animate({
'stroke-dashoffset': 0
}, 1000, 'easOutBounce');
console.log('on');
}, function() {
/* Stuff to do when the mouse leaves the element */
$(this).find('circle')
.stop()
.animate({
'stroke-dashoffset': pathLen
}, 1000, 'easOutBounce');
});
});
感谢您的宝贵时间!
【问题讨论】:
-
第一步:想知道“我该怎么做”,没有 jquery。 (正如你所发现的)。然后第二步总是可以“如果我使用 jQuery 可以更简洁地完成”。从“我如何在 jquery 中执行此操作”开始,而没有它可能甚至不需要它的选项,可能永远找不到一个像样的解决方案(有时纯 JS 比 jQuery 更有效,就像在这种情况下)
标签: javascript jquery css svg