[英]Is there any performance effect when bind event to more svg elements in jquery?
I am binding mousemove event to each svg element(path, circle,etc,.) to get individual information for each elements (like tooltip ,obj info) . 我将mousemove事件绑定到每个svg元素(路径,圆等),以获取每个元素的单独信息(如tooltip,obj info)。 is it effect the performance ?
对性能有影响吗?
JS: JS:
var elements = $(this.GroupEle).children();
for (var j = 0; j < elements.length; j++) { //length may be 5000
$(elements[j]).index = i;
$(elements[j]).collection = objCollection;
// performance issue ??????????????
$(elements[j]).bind('mousemove', this.pointonChartMove);
}
I need to pass different data to handler for each element. 我需要将不同的数据传递给每个元素的处理程序。
for (var j = 0; j < elements.length; j++) { //length may be 5000
//need to pass index and collection data to handler
$(elements[j]).index = i;
$(elements[j]).collection = objCollection;
$(elements[j]).bind('mousemove', this.pointonChartMove);
}
Pls suggest any other to achieve this???? 请提出任何其他建议来实现这一目标吗????
Depending on the number of child elements you could see quite a performance hit. 根据子元素的数量,您可能会发现性能受到很大影响。 You could use a single delegated event handler on a parent element to help the situation:
您可以在父元素上使用单个委派事件处理程序来解决这种情况:
$(this.GroupEle).on('mousemove', '.child-selector', this.pointonChartMove);
You would obviously need to change .child-selector
to something relevant to your code. 您显然需要将
.child-selector
更改为与您的代码相关的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.