Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 根据背景图像调整div的大小_Javascript_Jquery_Css_Css Transitions - Fatal编程技术网

Javascript 根据背景图像调整div的大小

Javascript 根据背景图像调整div的大小,javascript,jquery,css,css-transitions,Javascript,Jquery,Css,Css Transitions,我需要动态调整div的高度以显示其背景图像。我正试图让这个工作,所以我可以做的CSS转换技巧,你鼠标在一个div和背景放大,但我的图像将有不同的大小。感谢您的帮助。。。我卡住了 CSS: .dynaimage{ 宽度:80%; 背景图像:url(“变量图像”); 背景尺寸:100%;边距:0自动; } HTML: 上面的div应该取其背景图像的高度 使用img标签,而不是背景图像来执行此操作的方法 您需要将每个图像包装在一个div中。将div设置为overflow:hidden。图像宽度必

我需要动态调整div的高度以显示其背景图像。我正试图让这个工作,所以我可以做的CSS转换技巧,你鼠标在一个div和背景放大,但我的图像将有不同的大小。感谢您的帮助。。。我卡住了

CSS:


.dynaimage{
宽度:80%;
背景图像:url(“变量图像”);
背景尺寸:100%;边距:0自动;
}
HTML:


上面的div应该取其背景图像的高度


使用
img
标签,而不是
背景图像来执行此操作的方法

您需要将每个图像包装在一个div中。将div设置为
overflow:hidden
。图像宽度必须为100%;使用
transform:Scale(x)
缩放
img
;使用div的宽度设置图像的宽度

这里有一个演示

.img wrap{
溢出:隐藏;
显示:内联块;
/*宽度:20%*/
}
.img包裹img{
宽度:100%;
-webkit转换:1s;
-moz跃迁:1s;
-ms转换:1s;
-o-转变:1s;
过渡:1s;
}
.img wrap:悬停img{
转换:比例(1.2);
}

这比我脑子里的结容易多了!Thnx!
<style>
.dynaimage{
    width:80%;
    background-image:url('variable-image');
    background-size:100%; margin:0 auto;
}

</style>
<div class="dynaimage"></div>
<p>The above div should take the height of its background image</p>