html - 单击后包含 HTML 图像大小

标签 html css

我希望在点击图片后包含我的图片尺寸, 目前它们显示得比我希望它们显示的要大。

示例:http://messaages.com/post/144951542174

HTML:https://gist.github.com/anonymous/4f09e3306f9b28ee0dce286342c51c7e

我在代码中尝试过各种大小,但我似乎无法更改它。

最佳答案

如果您想在点击图片后更改图片大小,您需要使用 javascript 来更改 css。

<img onclick="imageChange(this)" style="width: 200px; cursor: pointer;" src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png">

<script>
window.imageChange = function(image) {
        if (image.style.width === "200px") {
        image.style.width = "100px";
    } else {
        image.style.width = "200px";
    }
}
</script>

JS fiddle :https://jsfiddle.net/ws12fqzc/

关于html - 单击后包含 HTML 图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37556418/

相关文章:

javascript - 在多个 TBODY 中更改 TR 的替代颜色

javascript - 如何在JSPDF中为pdf.cell应用css

jquery - 动画元素从一个列表移动到另一个

javascript - 单击按钮添加编辑器时,summernote 注释弹出窗口出现在左上角

html - 不同的列表项

javascript - DOM : How to detect a new child elements?

html - 将 MouseOn 与 CSS 链接悬停相结合

css - *标签如何在CSS中使用?

html - header (<h2>) 标记内的换行符 (<br/>)

php - WordPress 主题未正确显示图像