Javascript 图像的奇怪倾斜行为
我有一个在firefox中运行的函数:Javascript 图像的奇怪倾斜行为,javascript,css,google-chrome,Javascript,Css,Google Chrome,我有一个在firefox中运行的函数: function widthimg() { var wheight = document.getElementById('recent-img1'); console.log(wheight.clientHeight); document.getElementById('recent-img2').style.height = wheight.clientHeight +'px';
function widthimg() {
var wheight = document.getElementById('recent-img1');
console.log(wheight.clientHeight);
document.getElementById('recent-img2').style.height = wheight.clientHeight +'px';
}
但不是在chrome中,chrome完全不显示图像(高度为0的图像)
奇怪的是,这两种元素都是图像:
<div class="col-lg-6 col-sm-6 margin-top-60 zoominmouse">
{{HTML::image('images/recentprojects1.png','recent',array('class' => 'img-responsive img-center image-popup-vertical-fit', 'id' => 'recent-img1')) }}
</div>
<div class="col-lg-6 col-sm-6 margin-top-60 zoominmouse" id="test">
{{ HTML::image('images/pricing1.png','recent',array('class' => 'img-responsive img-center image-popup-vertical-fit', 'id' => 'recent-img2')) }}
</div>
现在我将clientHeight传递给clientHeight,这对我来说很有意义,但这两种浏览器都不适用
所以我的三个问题是:
- 我该怎么做才能使该功能在chrome中工作
- 为什么我不能把clientHeight传给clientHeight
- 是否有可能使用css使两幅图像都达到img1的高度
img1.onload = function() {
img2.height = img1.height;
}
可以这样使用:
function widthimg() {
var wheight = document.getElementById('recent-img1');
console.log(wheight.clientHeight);
document.getElementById('recent-img2').clientHeight = wheight.clientHeight;
console.log(document.getElementById('recent-img2').clientHeight);
}
<body onload="widthimg()">
// rest of your html
</body>
函数宽度img(){
var wheight=document.getElementById('recent-img1');
控制台日志(wheight.clientHeight);
document.getElementById('recent-img2')。clientHeight=wheight.clientHeight;
console.log(document.getElementById('recent-img2').clientHeight);
}
//剩下的html
clientHeight是只读的,只需使用height@dandavis只是高度不起作用。高度必须起作用,而且它的R/W启动。。。无论是什么道具,在测量之前确保图像已加载…调用你的方法onload,它应该会工作。我说得再好不过了。
function widthimg() {
var wheight = document.getElementById('recent-img1');
console.log(wheight.clientHeight);
document.getElementById('recent-img2').clientHeight = wheight.clientHeight;
console.log(document.getElementById('recent-img2').clientHeight);
}
<body onload="widthimg()">
// rest of your html
</body>