我正在使用 jquery-imagetool 插件来裁剪图像。我的 jquery 代码如下所示:
$('div.image img').imagetool({
viewportWidth: 171,
viewportHeight: 267
})
我想从 div.image 元素的 css 中获取 viewportWidth 参数,因此我需要获取当前元素 (img) 并对其调用parent()。
谁能帮我吗?
最佳答案
使用每个单独处理图像,然后可以获得 div 的宽度。
$('div.image img').each(function() {
var width = $(this).closest('div.image').width();
$(this).imagetool({
viewportWidth: width,
viewportHeight: 267
});
});
关于jquery 来自函数参数的当前元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10123146/