我现在停留在此场景中。获取特定Div的宽度,然后显示以下代码
我有3个帖子缩略图不同尺寸。
根据用户的屏幕大小,我只需要显示一个图像。我不喜欢使用CSS媒体查询或通过CSS调整相同的图像,因为它变得扭曲。无论如何,它是否有可能实施使用PHP IF?
是这样的:
IF博客帖子宽度== 360像素 显示<?php the_post_thumbnail('post-thumbnails2200px', array('id' => "FeatureImage")); ?>
否则如果.blogpost宽度== 300像素 显示<?php the_post_thumbnail('post-thumbnails1280px', array('id' => "FeatureImage")); ?>
否则如果.blogpost宽度== 250像素 显示<?php the_post_thumbnail('post-thumbnails600px', array('id' => "FeatureImage")); ?>
这是html结构:
<div class="blogpost" id="blogpost">
<a class="post_title" href="<?php the_permalink() ?>" rel="bookmark" alt="<?php the_title(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail('post-thumbnails2200px', array('id' => "FeatureImage")); ?>
</a>
</div>
需要Javascript获得浏览器的尺寸。您可以在AJAX发送用户的视口大小后加载内容,但该解决方案闻到 – 2013-04-20 11:56:31
,您可以使用GET参数发送缩略图'width'并使用它。 – mehdi 2013-04-20 11:57:09
如果分辨率改变,图像不会随着它改变(浏览器的大小调整) – 2013-04-20 13:06:20