推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
Exin

求准确地显示图片的方法

  •  
  •   Exin · Jun 12, 2015 · 2404 views
    This topic created in 4014 days ago, the information mentioned may be changed or developed.
    有许多尺寸各异的png图片,需要在一个固定尺寸的div内通过一个img(id="pic")显示。
    图片之间通过函数切换,输入参数通过文本框获取。

    function display(id){
    document.getElementById("pic").src=id+".png"
    }

    第一个图片能按原尺寸显示,再切换之后的图片的尺寸则变成与第一个相同了。
    注意到CSS样式里出现了!important后缀,我尝试在display函数内尝试重设pic尺寸,但是不管用。
    Supplement 1  ·  Jun 12, 2015
    已自行解决。捣鼓了3小时
    3 replies    2015-06-13 21:19:05 +08:00
    webjin
        1
    webjin  
       Jun 13, 2015
    还行吧
    cctrv
        2
    cctrv  
       Jun 13, 2015
    不知道你的 CSS 怎么写。
    但是,应该是这样的。

    src=id+".png"+"?"+id;(防缓存)

    CSS:
    width: 固定值px;
    height: auto;
    Exin
        3
    Exin  
    OP
       Jun 13, 2015
    @cctrv 这样写不行呢……
    我最后用setAttribute('style','width:auto !important;height:auto !important;)以及一段获取原文件尺寸的js搞定的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1186 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 17:47 · PVG 01:47 · LAX 10:47 · JFK 13:47
    ♥ Do have faith in what you're doing.