数据属性刷新画布
Data attribute refresh canvas
我有一个通过数据百分比绘制的圆形。如果90%,它将绘制形状的90%。
我的想法是每秒钟删除这个正方形的1%,问题是设置数据属性不起作用,如果我通过DOM进行设置,形状就不会自我更新。
$(document).ready(function() {
var charta = $(".chart");
var value = charta.data("percent");
charta.data("percent", "200");
<div class="chart" data-percent="90"></div>
当数据属性发生变化时,没有触发的事件
因此,将data-percent
属性从90更改为200总是不会引起注意。
您可以创建一个自定义jQuery事件,在更改data-percent
时触发该事件。。。
// tell the .chart class to listen for a custom event
// called "changedDataAttribute"
$('.chart').on('changedDataAttribute', function(e){
// call a function to redraw the chart
redrawMyChart(this.id,$(this).data('percent'));
});
// chain jquery commands to first change data-percent to 200
// and then trigger the custom "changedDataAttribute" event
$('.chart').data("percent",200).trigger('changedDataAttribute');
// redraw the chart with id==chartId
function redrawMyChart(chartId,newPercent){
// now redraw your chart with id==chartId at newPercent
}
。。。但是,除非出于某种原因需要事件层,否则没有必要添加它
相反,只要更改data-percent
,就可以直接调用redrawMyChart
。
// redraw the chart with id==chartId
function redrawMyChart(chartId,newPercent){
// now redraw at newPercent
}
相关文章:
- 序列化数据属性中对象的最可靠方法
- jQuery最近父级的数据属性选择器
- delete在Object上效率低下,但在DOM Element's的数据属性,与null out相比
- 数据属性仅在切换设备模式下工作
- 函数jquery.html()不提供数据属性集值
- 在数据属性上进行下拉自动选择
- JavaScript-获取数据属性的值返回未定义的值
- 如何替换数据属性中的特定字符串单词
- 使用数据属性将HTML数据复制到另一个元素
- JQGrid使用服务器编辑后的更新数据刷新数据
- 带有CSS的数据属性就没那么有用了
- 查找所有TD标签并读取其数据属性
- 使用jQuery获取第N个元素的数据属性值
- 使用自定义数据属性或将数据绑定到处理程序来处理事件
- 数据属性有没有更干净的方法
- 是否可以使用CSS分配数据属性
- 根据jquery数据属性值进行查询
- 使用jQuery在select选项上设置HTML数据属性
- 数据属性刷新画布
- <对象> 代码在 Chrome 中更改其数据属性时不会刷新