【发布时间】:2015-10-29 21:35:27
【问题描述】:
我在http://mixchuti.cz/category/obrazky/ 上的缩略图有问题
我有一个超过 img 宽度大小 (250x250px) 的 div 和不同大小的特色图片。溢出很好,但我需要将图像高度或宽度设置为 div 的 100%,这取决于更高的参数。
有关我正在尝试的更多信息,这是我的工作代码:
<script>
$(function(){
$('.wp-post-image').ready(function() {
if ($(this).css('height') > $(this).css('width')) {
$(this).css('width','100%')
} else {
$(this).css('height','100%')
}
});
});
</script>
前面是经典的 WP 缩略图:
<?php if(has_post_thumbnail()):the_post_thumbnail('featured_post_image'); endif; ?>
【问题讨论】:
-
我不确定你在问什么,你想让图像适合 div 的大小吗?
-
是的,但只是更高的维度。由于溢出,其余图像将不显示。
-
$(this).css('width') 返回图像的宽度,查看 jquery doc 了解更多信息api.jquery.com/css 所以你不需要任何变量
-
我怀疑失败与您的选择器 $('.obimg img') 有关。您应该测试该函数是否被调用。例如。通过放置 console.log("do it");在你的 if 语句前面
-
我更改了代码(并编辑了这篇文章),但我不确定将控制台日志放在哪里。你能用这条线把上面的线复制过来吗?