简体   繁体   English

如何使JQuery插件“圆角”起作用? (或建议一个更好的选择)

[英]How can I make the JQuery addon “Rounded Corners” work? (or suggest a better option)

I am having problems getting the JQuery Library "Rounded Corners" to work in IE. 我在让jQuery库“ Rounded Corners”在IE中工作时遇到问题。 All I want to do is simulate border-radius on a div in Internet Explorer. 我要做的就是在Internet Explorer中的div上模拟边界半径。 I have gotten the addon to work in Firefox, but I think that's because this addon takes advantage of that CSS property. 我已经使该插件在Firefox中工作,但是我认为这是因为该插件利用了CSS属性。 I have also gotten it to work in IE, but only on basic DIVs. 我也可以在IE中使用它,但只能在基本DIV上使用。

Here is the addon's home page: http://jquery.malsup.com/corner/ 这是插件的主页: http : //jquery.malsup.com/corner/

Here is the code: 这是代码:

CSS 的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]-->

HTML 的HTML

<div id="mydiv"></div>
<div id="ie-shadow">&nbsp;</div>

Javascript Java脚本

<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>

I'm going to suggest a better option: PIE.htc. 我将建议一个更好的选择:PIE.htc。

Download it here: http://css3pie.com/ 在此处下载: http : //css3pie.com/

USAGE 用法

Extract the PIE.htc file to your root directory. 将PIE.htc文件提取到您的根目录。 In your CSS, you can do the following: 在CSS中,您可以执行以下操作:

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

NOTE: The location of the PIE.htc is relative to the HTML file, NOT the CSS file. 注意: PIE.htc的位置是相对于HTML文件而不是CSS文件的。 Also, you may ONLY use the shorthand of border-radius . 另外,您只能使用border-radius的简写。 You cannot specify border-top-left-radius , for example, when using the hack for IE. 例如,在将hack用于IE时,不能指定border-top-left-radius

You can take it a step further by adding an IE conditional (PIE.htc does not play nice with IE9+): 您可以通过添加IE条件代码(PIE.htc在IE9 +上不能很好地发挥作用)进一步采取以下步骤:

.round-em {
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  border-radius: 10px;
}

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

EDIT 编辑

Since you cannot load the PIE.htc script across domains, you can use PIE.js. 由于无法跨域加载PIE.htc脚本,因此可以使用PIE.js。 Here is the link: http://css3pie.com/documentation/pie-js/ 这是链接: http : //css3pie.com/documentation/pie-js/

There is a hosted version available here: http://cdnjs.cloudflare.com/ajax/libs/css3pie/1.0beta5/PIE.js 这里有托管版本: http : //cdnjs.cloudflare.com/ajax/libs/css3pie/1.0beta5/PIE.js

HOW TO USE PIE.JS 如何使用PIE.JS

First, call the script via an IE conditional: 首先,通过IE条件调用脚本:

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

Next, use jQuery to iterate through each of the elements that have round-em as a class. 接下来,使用jQuery遍历以round-em为类的每个元素。 Then, use the PIE.attach method and pass in the this context as a parameter. 然后,使用PIE.attach方法并将this上下文作为参数传递。

$(function() {
  if (window.PIE) {
    $('.rounded').each(function() {
      PIE.attach(this);
    });
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM