jquery 从选择链中的 $this 中获取属性值

jquery get attr value from within $this in selection chain

正在尝试获取正在选择的元素内的属性值的高度。

尝试了几种方法,但 none 对我有用。

$(".gauge_fill").stop().animate({height : $(this).attr('fill_height')},2000);

$(".gauge_fill").stop().animate({height : function(){return $(this).attr('fill_height')}},2000);

<div class="gauge_fill" fill_height="200px">

页面上有多个 div class gauge_fill 具有不同的值。目标是让 200px 用于动画中的高度。

可能有更优雅的方法来完成此操作,但要访问各个元素以便您可以提取这些属性,只需迭代这些元素,然后 this 将确实引用该元素:

$(".gauge_fill").each(function(){
  $(this).stop().animate({height : $(this).attr('fill_height')},2000);
})