Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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 使用响应性设计使图像流畅?_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 使用响应性设计使图像流畅?

Javascript 使用响应性设计使图像流畅?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,事实上,我知道如何用响应性设计流畅地呈现图像。但是,我的问题并不简单。我使用父级div的缩放宽度函数来附加图像的宽度,如下所示: function OnImageLoad(evt){somthing....} <div class="parent"> <img style="left: 0px; top: -20px;" onload="OnImageLoad(event);" src="http://4.bp.blogspot.com/-pHWQ1Wp63GQ/Uk3TJ

事实上,我知道如何用响应性设计流畅地呈现图像。但是,我的问题并不简单。我使用父级
div
的缩放宽度函数来附加
图像的宽度,如下所示:

 function OnImageLoad(evt){somthing....}
<div class="parent">
 <img style="left: 0px; top: -20px;" onload="OnImageLoad(event);" src="http://4.bp.blogspot.com/-pHWQ1Wp63GQ/Uk3TJLa9FbI/AAAAAAAAACg/_JUXOxweYY8/s1600/edu2.jpg" width="270" height="175">
</div>

帮我修一下。谢谢你的帮助。

我会给这些图像设置一个特殊的类(如果不是所有图像都需要触发的话)。 (在调整大小功能中使用计时器,以支持浏览器多次触发。)

但另一方面,如果您只想缩放图像。 在本例中,通过填充底部,比率保持不变

img{
    width:100%;
    height:0;
    padding-bottom:66%;
}

与其使用javascript来获得流动性,为什么不能以百分比的形式设置图像的高度和宽度?因为图像是从帖子加载来制作缩略图的。为了确保缩略图质量,我必须使用缩放功能从父div生成图像大小。您可以使用window.onresize并在图像集合中迭代。谢谢Arun。但您可以提供更多详细信息?调整窗口大小时会触发window.onresize。捕获事件并在其中为所有缩略图运行缩放功能,就像onload事件对每个缩略图所做的那样。。试试这个:)我试过了,但结果还是一样。感谢您尝试帮助我。请在此处使用附件帮助我:。谢谢
$(window).resize(function(){

      //get the function out of the onload attribute
      var onloadFunction = $("img.[specialclass]").attr("onload");
      //Execute it
      eval(onloadFunction);
});
img{
    width:100%;
    height:0;
    padding-bottom:66%;
}