如何让JQuery插件"Rounded Corners"工作?(或建议更好的选择)

Ian*_*Ian 1 html javascript css jquery css3

我在使用JQuery Library"Rounded Corners"在IE中工作时遇到了问题.我想要做的就是在Internet Explorer中模拟div上的border-radius.我已经在Firefox中使用了插件,但我认为这是因为这个插件利用了CSS属性.我也让它在IE中工作,但仅限于基本的DIV.

这是插件的主页:http://jquery.malsup.com/corner/

这是代码:

CSS

<style>
#mydiv { /*basic CSS for the DIV*/
    border: 1px solid #76B4EA;
    border-bottom: none;
    box-shadow: inset -10px 10px 30px #e0e0e0, 2px -2px 1px #707070;
    background: #fff;
    width: 200px;
    height: 80px;
    margin-top: 21px;
    z-index: 3;
    margin-left:2px; 
    position: absolute
}
#ie-shadow { /*code for a cross-browser shadow*/
    display: none;
}
</style>
<!--[if lte IE 8]>/*more code for the cross-browser shadow*/
<style>
#ie-shadow {
    display: block;
    position: absolute;
    top: 17px;
    left: 2px;
    width: 200px;
    height: 80px;
    z-index: 1;
    background: #000;
    filter:progid:DXImageTransform.Microsoft.Blur(PixelRadius='2', MakeShadow='true', ShadowOpacity='0.40');

}
</style>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

HTML

<div id="mydiv"></div>
<div id="ie-shadow">&nbsp;</div>
Run Code Online (Sandbox Code Playgroud)

使用Javascript

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://malsup.github.com/jquery.corner.js"></script>
<script type="text/javascript">
$('#mydiv').corner("rounded top 10px keep cc:transparent");
</script>
Run Code Online (Sandbox Code Playgroud)

Nic*_*nek 6

我打算建议一个更好的选择:PIE.htc.

在这里下载:http://css3pie.com/

用法

将PIE.htc文件解压缩到根目录.在CSS中,您可以执行以下操作:

.round-em {
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  border-radius: 10px;
  behavior: url('PIE.htc');
}
Run Code Online (Sandbox Code Playgroud)

注意: PIE.htc的位置是相对于HTML文件,而不是CSS文件.此外,您可能只使用简写border-radius.border-top-left-radius例如,您无法指定在IE中使用hack时.

您可以通过添加IE条件更进一步(PIE.htc与IE9 +不兼容):

.round-em {
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  border-radius: 10px;
}
Run Code Online (Sandbox Code Playgroud)

<!--[if lt IE 9]> .round-em { behavior: url('PIE.htc'); } <![endif]-->

编辑

由于无法跨域加载PIE.htc脚本,因此可以使用PIE.js. 这是链接:http://css3pie.com/documentation/pie-js/

这里有一个托管版本:http://cdnjs.cloudflare.com/ajax/libs/css3pie/1.0beta5/PIE.js

如何使用PIE.JS

首先,通过IE条件调用脚本:

<!--[if lt IE 9]> <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/css3pie/1.0beta5/PIE.js"></script> <![endif]-->

接下来,使用jQuery迭代每个round-em作为类的元素.然后,使用该PIE.attach方法并将this上下文作为参数传递.

$(function() {
  if (window.PIE) {
    $('.rounded').each(function() {
      PIE.attach(this);
    });
  }
});
Run Code Online (Sandbox Code Playgroud)