【问题标题】:Image Height Width Problem图像高度宽度问题
【发布时间】:2010-09-17 23:27:56
【问题描述】:

如何使用 jQuery 更改图像分辨率。我使用 css/php 在正文背景上应用了图像。现在我想将屏幕高度和宽度应用于图像,以便图像在全窗口中显示。 实际上我没有使用重复样式。

使用的代码是:

 <style type="text/css">
                    <?php
                            global $post;   
                            if ( has_post_thumbnail($post->ID) ) { 
                                    $image_id = get_post_thumbnail_id($post->ID);
                                    $bg_src = wp_get_attachment_image_src( $image_id, 'full');
                            ?>
                        body { background: #000000 url("<?php echo $bg_src[0]; ?>") no-repeat center top fixed !important; }
                            <?php } else { ?> 
                        body { background: #000000 url("<?php bloginfo('template_directory') ?>/img/bg_img.jpg") no-repeat center top fixed ; }
                            <?php } ?>
        </style>       

我使用它获取屏幕高度和宽度,我们无法理解在该图像上实现它的内容。

var p_browserHeight= screen.height;
        var p_browserWidth= screen.width;
        jQuery('body.archive').css('height',p_browserHeight+'px' );
        jQuery('body.archive').css('width',p_browserWidth+'px' );

【问题讨论】:

  • 你知道如果你同时改变你会弄乱纵横比吗?如果你只改变宽度,高度将是任何需要的
  • CSS3 最后有一个 background-size 属性。一旦在浏览器中得到广泛支持,将高度/宽度设置为 100% 会更容易。
  • 是的。 '在那之前,你需要一种不同的方法。

标签: php javascript jquery html css


【解决方案1】:

你可以在你的body标签之后添加这个html:

<img src='img/bg_img.jpg' style='display:none;' id='image_hidden'/>

并使用 jquery 获取此图像的高度/高度

【讨论】:

    【解决方案2】:

    您不能使用 css 更改背景图像的大小。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-12
      • 1970-01-01
      • 2021-10-27
      • 2012-03-15
      • 2012-08-07
      • 1970-01-01
      • 1970-01-01
      • 2020-06-25
      相关资源
      最近更新 更多