javascript - 获取每个单独的 div 的数据值

标签 javascript jquery html css

我正在使用几个插件来使用 JavaScript 制作进度条动画。

我在 HTML 中设置每个数据值以避免每次都在 JavaScript 中定义它。

<div class="progress-circle" data-value="0.65">

我想获取数据值以进行动画处理并每次都停在该值处,但我目前拥有的代码将所有这些值都停在第一个 div 值处。

    var el = $('.progress-circle'),
    inited = false;

    el.appear({ force_process: true });

    el.on('appear', function() {
      if (!inited) {
        el.circleProgress({ value: el.attr('data-value') });
        inited = true;
      }
    });

    $('.progress-circle').circleProgress({
        size: 80,
        startAngle: -Math.PI / 4 * 2,
        lineCap: "round",
        fill: { color: "#64B46E" } 
    }).on('circle-animation-progress', function(event, progress, stepValue) {
    $(this).find('.inner').text(String(stepValue.toFixed(2)).substr(2)+ '%');
});

我怎样才能让它使用每个 div 唯一的数据值属性?

最佳答案

$('your-div').each(function() {
   //do something with $(this).data('value');
   //other way to get is $(this).attr('data-value');
});

关于javascript - 获取每个单独的 div 的数据值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33463284/

相关文章:

javascript - 为什么没有引发点击事件?

javascript - Reactjs:将 React 代码粘合到旧的 javascript 代码中

javascript - 没有浏览器是否可以进行ajax调用?

html - 增加 Font Awesome 图标

javascript - javascript 类中的共享回调处理程序

javascript - 为什么 "foo = foo || {};"不起作用?

javascript - 获取 2 个单词之间的字符串,其中也包含该单词

java - IE8下jsp页面div截图的方法

javascript - react : Big Calendar Font Style

javascript - 如何使用哈希标签 ("a name") 转到页面上的位置但在顶部占固定元素?