jQuery-在.css()中选择$(this)



我想执行以下代码: -

$('.someclass').css {
  width: Math.round(($(this).parent().width() / $(this).parent().height()) * $(this).parent().parent().width())
}

但我未能得到结果。

如果要根据当前元素计算给CSS属性的值,则可以为css()方法提供函数,例如:

$('.someclass').css('width', function() {
  var $parent = $(this).parent();
  return Math.round(($parent.width() / $parent.height()) * $parent.parent().width())
});

最新更新