【发布时间】:2013-05-06 19:56:35
【问题描述】:
我想画一条从 .class 元素到 class 元素的画布线。到目前为止,我可以通过 elements.first() 和 elements.first() 引用类中的开始和结束元素。
困难在于我想使用需要起点和终点的 quadraticCurveTo。结束点是 .class 中的下一个元素。
$('.myclass').chainlines();
$.fn.chainlines = function(){
context.moveTo($(this).first().position().left+15,$(this).first().position().top+20);
$(this).each(function(){
next = $(this).next();
context.quadraticCurveTo($(this).first().position().left+60,
$(this).position().top+25,$(next).position().left+15,$(next).position().top+15);
});
};
我有一个 jsfiddle 示例,我需要将其扩展为链式 .见LINK。
这对我不起作用。
【问题讨论】:
-
我看不出链接的小提琴与这段代码 sn-p 有什么关系。此外,该代码 sn-p 不是有效的 jQuery。
-
是什么让你认为在 jQuery 中有一个实际的
.id()方法,你试过.prop('id') -
@adeneo id 不是属性而是属性。
-
@adeneo 我很反对 Juhana,顺便说一句,'id' 应该始终保持默认值,所以没有理由在这里使用 .prop()。但是对于 'id',这是一个错误的争论,因为我们应该使用 DOM 元素的属性来代替
-
@roasted,所以你建议使用
element.getAttribute('id')而不是element.id?因为这就是$(..).attr('id')和$(..).prop('id')之间的区别。prop和attr都应该可以正常工作,但我会坚持使用prop以保持一致性。