Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.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_Css_Fallback_Shim - Fatal编程技术网

Javascript “好”;背景尺寸:封面“;DIV上跨浏览器兼容性的后备方案/垫片/技巧?

Javascript “好”;背景尺寸:封面“;DIV上跨浏览器兼容性的后备方案/垫片/技巧?,javascript,css,fallback,shim,Javascript,Css,Fallback,Shim,因此,我使用background size:cover来实现背景图像的理想效果,该图像可以缩放到应用到的div的任何大小,同时保持纵横比。为什么使用这种方法?根据相关WordPress帖子中设置为图像的内容,使用内嵌CSS动态地通过PHP将图像应用为背景 所以一切都很好,但是否有任何回退,以确保这将至少在IE8工作?可能是一些Javascript修复 已经尝试过,但没有效果,因为他们只将图像应用于页面的背景 您可以看到它的作用。在IE8或以下版本中,作为定义了宽度/高度的div的子级插入的前景图

因此,我使用
background size:cover
来实现背景图像的理想效果,该图像可以缩放到应用到的div的任何大小,同时保持纵横比。为什么使用这种方法?根据相关WordPress帖子中设置为图像的内容,使用内嵌CSS动态地通过PHP将图像应用为背景

所以一切都很好,但是否有任何回退,以确保这将至少在IE8工作?可能是一些Javascript修复

已经尝试过,但没有效果,因为他们只将图像应用于页面的背景


您可以看到它的作用。

在IE8或以下版本中,作为定义了宽度/高度的div的子级插入的前景图像将是唯一的解决方法:

<!doctype html>
<html lang="en">
<head>
    <title>Dynamic Image Sizing</title>
<style type="text/css">
html, body { margin:0; padding:0; width:100%; height:100%; overflow:hidden; text-align:left; }
#pseudobg { position:absolute; z-index:1; width:100%; height:100%; }
#scroller { position:absolute; width:100%; height:100%; top:0; left:0; overflow:auto; z-index:2; }
#dyndiv { position: absolute; left: 50%; width: 200px; height: 300px; }
</style>
</head>
<body>

<div id="scroller">
  <!-- Insert your content here -->
  <div id="dyndiv">
    <img id="pseudobg" src="http://www.stackoverflow.com/favicon.ico" alt="" title="" />
  </div>
</div>
</body>
</html>

动态图像大小调整
html,正文{边距:0;填充:0;宽度:100%;高度:100%;溢出:隐藏;文本对齐:左;}
#伪BG{位置:绝对;z索引:1;宽度:100%;高度:100%;}
#滚动条{位置:绝对;宽度:100%;高度:100%;顶部:0;左侧:0;溢出:自动;z索引:2;}
#dyndiv{位置:绝对;左侧:50%;宽度:200px;高度:300px;}
如果这不等同,请寻求进一步的帮助

演示:


我以前尝试过这个答案,但它不能作为背景尺寸:封面;这是意料之中的,事实上它确实使图像适合所选的尺寸,但它没有将多余的部分剪裁到新的尺寸,这是我从“封面”选项中所期望的。我的解决方案如下:


.带背景尺寸
{
背景图像:url('http://img1.jurko.net/wall/paper/donald_duck_4.jpg');
背景位置:中心;
/*过滤器:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=)http://img1.jurko.net/wall/paper/donald_duck_4.jpg,sizingMethod='scale');
它没有像预期的那样起作用*/
宽度:200px;
高度:100px;
/*使背景图像覆盖该区域,并剪裁多余部分*/
背景尺寸:封面;
}
唐老鸭!

如果您需要缩小图像的大小,而不是增大图像的大小,这种方法不起作用。我发现避免使用Javascript的最佳方法是将两个图像叠加在一起,悬停时使顶部图像透明。所有其他涉及调整原稿大小的方法(例如,
背景大小
)在IE中似乎都失败了

CSS:

HTML:



.social btn container:hover>.top btn
部分在IE怪癖模式下工作,该模式似乎不支持
不透明度
,如果使用
:hover{visibility:hidden}
当可见性变为隐藏时,hover变为false,导致闪烁。(外部div也会定位图像。)我已经在FF23、IE标准和怪癖(让IE 10模拟7、8和9)、Opera和Safari中测试了这一点。

在IE8或以下版本中使用分隔的
背景:
代码:

-webkit示例:

background: url('img/habesha.jpg') no-repeat center center;
-webkit-background-size: cover;
background-image:url('img/bright_switch.jpg');
background-repeat: no-repeat;
background-position: 50% 50%;
background-size: 100% 100%;
-在IE中尝试:

background: url('img/habesha.jpg') no-repeat center center;
-webkit-background-size: cover;
background-image:url('img/bright_switch.jpg');
background-repeat: no-repeat;
background-position: 50% 50%;
background-size: 100% 100%;
详情如下:

background-image:url('img/bright_switch.jpg');
background-repeat: no-repeat;
background-position: 50% 50%;
background-size: 100% 100%;