- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 jquery globalcss 插件来更改全局样式表。它不处理不透明度和 IE。
我一直在尝试让它正常工作,但运气不佳。这是我强制插件尝试理解 IE 样式不透明度的尝试。
function changeCss (property, value, target) {
if (property === "opacity") {
$(target).globalcss("filter","alpha(opacity="+value*100+")");
/* For IE 8 (and 9, 10, 11?). Don't miss the added quotes */
$(target).globalcss("-MS-filter","\"progid:DXImageTransform.Microsoft.Alpha(Opacity="+value*100+")\"");
}
$(target).globalcss(property,value);
}
废话。如果有人可以提供帮助,那就太好了。谢谢。
我将插件粘贴在这里,因为它不再位于其原始站点上:
/*
* Global Stylesheet jQuery Plugin
* Version: 0.1
*
* Enables CSS modification that uses a 'global' stylesheet, rather than inline CSS.
*
* Copyright (c) 2009 Jeremy Shipman (http://www.burnbright.co.nz)
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* INSTRUCTIONS:
* use in the same way as the jQuery css function. Eg:
* $("some selector").globalcss("style","value");
*
* use the globalsetylesheet.print() function to return a string of the global stylesheet
*/
(function($) {
//global singleton class for
globalstylesheet = new function globalStylesheet(){
if(!document.styleSheets){
alert("document.Stylesheets not found");
return false;
}
var sheet = null;
var setrules = Array(); // rule cache
//set up a dummy noded
var cssNode = document.createElement('style');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.media = 'screen';
cssNode.title = 'globalStyleSheet';
document.getElementsByTagName("head")[0].appendChild(cssNode);
//find the newly created stylesheet and store reference
for(var i = 0; i < document.styleSheets.length; i++){
if(document.styleSheets[i].title == "globalStyleSheet"){
sheet = document.styleSheets[i];
}
}
//set a CSS rule
this.setRule = function setRule(selector,ruleText){
if(setrules[selector] != undefined){
return setrules[selector];
}else{
if(sheet.addRule){ // IE
sheet.addRule(selector,ruleText,0);
}else{
sheet.insertRule(selector+'{'+ruleText+'}',0);
}
setrules[selector] = this.getRule(selector);
}
return setrules[selector];
}
//get a saved CSS rule
this.getRule = function getRule(selector){
if(setrules[selector] != undefined){
return setrules[selector];
}else{
var rules = allRules();
for(var i = 0; i < rules.length; i++){
if(rules[i].selectorText == selector){
return rules[i];
}
}
}
return false;
}
//helper function to get all rules
function allRules(){
if(sheet.cssRules){ //IE
return sheet.cssRules;
}else{
return sheet.rules;
}
}
//print out the stylesheet
this.print = function print(){
var styleinfo = "";
var rules = allRules();
for(var i = 0; i < rules.length; i++){
styleinfo+= rules[i].cssText+"\n"
}
return styleinfo;
}
//use jQuery's css selector function to set the style object
this.css = function css(jquery,key,value){
rule = this.setRule(jquery.selector,key+":"+value+";");
jQuery(rule).css(key,value);
}
}
//hook new function into jQuery
jQuery.fn.extend({
globalcss : function globalcss(key,value){
globalstylesheet.css(this,key,value);
}
});
})(jQuery);
编辑:我创建了一个 jsbin 现场演示。请在不同的浏览器中进行比较。 http://jsbin.com/iqadu/edit
最佳答案
更新:
我下面的第一个想法不是问题。事实证明,这个问题要简单得多:确保在小于 1 的 float 前加一个零。也许这是由于 javascript 如何处理字符串值到数字的转换?无论如何,在“.5”之前添加一个零解决了这个问题。
// works
var property = "opacity";
var value = "0.5";
var target = ".transparency";
// doesn't work
var property = "opacity";
var value = ".5";
var target = ".transparency";
在这里查看工作代码:http://jsbin.com/ikore3 .顺便说一句,您原来的演示页面有一个 javascript 问题,大括号放在错误的位置。我也解决了这个问题。
以下是导致此问题的最初想法 - 结果证明不是问题
您可能会遇到与 jquery 无关的 IE 怪癖:为了使不透明度起作用,元素必须具有“layout”,这是一个 IE 特定的 bool 状态,由 CSS 触发,例如高度、宽度、缩放等。如果元素没有“布局”,则不透明度将不起作用。
解决方法是向元素添加特定的 CSS,以便为其提供“布局”。不确定这是否是您的情况,但通过添加提供布局的 CSS 属性之一并查看问题是否消失,很容易进行检查。
来自 http://joseph.randomnetworks.com/archives/2006/08/16/css-opacity-in-internet-explorer-ie/ :
But simply setting the filter/opacity value in IE isn’t enough. Turns out that IE requires an element to be positioned in order for filter/opacity to work. If your element doesn’t have a position you can work around this by adding ‘zoom: 1‘ to your CSS. There are other hacks to deal with this, zoom was the one I picked and it seems to work well enough.
In JavaScript you can find out if an element in IE has a position component by checking element.currentStyle.hasLayout. If hasLayout is false then the element has no CSS positioning.
If you want to learn more about this issue here is a reading list to get your started:
◦ Exploring OpacityStep-by-Step [broken link]
使用您的代码,这是一种可能的方法来确保如何测试这是否是您的问题:
function changeCss (property, value, target) {
if (property === "opacity") {
$(target).globalcss("filter","alpha(opacity="+value*100+")");
/* For IE 8 (and 9, 10, 11?). Don't miss the added quotes */
$(target).globalcss("-MS-filter","\"progid:DXImageTransform.Microsoft.Alpha(Opacity="+value*100+")\"");
$(target).globalcss("zoom","1"); // ensure the target has layout
}
$(target).globalcss(property,value);
}
更复杂的版本会检查缩放是否已经存在,只有在缺失时才添加它。您还可以检查 hasLayout property 并且只有在它为 false 时才设置缩放,只要你防御 hasLayout 根本不存在的非 IE 情况。
如果这不能解决问题,您能否发布 HTML 示例或 URL,以便我们重现问题,从而更容易提出修复建议?谢谢!
关于jquery globalcss IE 不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1665313/
我是网页设计新手。现在我遇到了我目前工作的 2 个网站的问题。我的模板只支持 Firefox 浏览器,不支持其他主流浏览器,如 IE、chrome、Opera、safari。 我试过一些 If IE
在我的 HTML 上,使用了下面的元标记来解决一些字体问题。我只想知道: 这两个元标记的含义相同吗?还是每一个都不一样? [以逗号分隔] [以分号分隔] 请解释一下。 最佳答案 Microsoft
这句话究竟是什么意思? 部分示例使用 ,分隔 IE 的版本,而有些使用 ; ;哪个是正确的? 订单IE=9; IE=8; IE=7; IE=EDGE有一些重要性,我想知道。 编辑:我正在使用 最佳答
这句话究竟是什么意思? 一些示例使用 ,分隔 IE 的版本,而有些使用 ; ;哪个是正确的? 订单IE=9; IE=8; IE=7; IE=EDGE有一定的重要性,我想知道。 编辑:我正在使用 最佳
在 IE 8 中,我们可以带出开发者工具。然后在顶部,有一个浏览器模式: IE 7 IE 8 IE 8 Compatibility View 所以如果 IE 7是强制页面显示为好像浏览器是 IE 7,
我认为不需要任何描述。我只需要我的 IE 11 单选按钮与 IE 8 中的一样,即颜色为 3-d 蓝色。在 IE 11 中,默认单选按钮是二维的,颜色为黑色。目前还没有解决这个问题。 最佳答案 检查这
我必须编写一个显示密码对话框的小程序。问题是对话框设置为始终在顶部,但是当用户单击 IE 窗口时,对话框仍然隐藏在 IE 窗口后面。并且由于对话框是模态的并且保持全部 IE 线程 IE Pane 不会
如何制作适用于所有 IE 浏览器的样式表。不只是 ie.css 中的 IE 8 本站主题的ie.css文件中只包含IE8样式。 最佳答案 他们这样做的原因是因为他们可能不支持 Internet Exp
使用有什么区别吗 ... 或者 ... ? 最佳答案 如果一种罕见的、神话般的浏览器被称为 ,就会有所不同。 Internet Explorer 6.66 被发现。 关于internet-explor
我试图在 IE7+8 中使用字体图标并遇到了一个问题,这个问题可以通过仅 IE7 的样式表轻松解决。长话短说,现在 IE7 和 IE9 都以某种方式运行我的仅 IE7 样式表(IE8 运行得很好)。我
我实现了上传的图片显示在网站上。为了 图片未正确上传意味着我将错误图片替换为 那?当我加载网站时,我遇到了 错误图像不存在的问题 定义,并且灯箱在 chrome 和 firefox 中加载 但它没有在
我有一个特殊的问题。我正在尝试“现代化”和为旧 IE 制作的旧应用程序,以便在 IE 11 中工作。但不知何故,CSS 类没有应用于 DOM 元素。 CSS 非常简单: .header { h
对于 IE 7 和 IE 8,IE 上 URL 的 2k 长度限制是否仍然存在? (后 IE 6 时代) 最佳答案 http://support.microsoft.com/kb/208427 似乎它
我们正在完善这个网站:dev.underglassframing.com 除了主要内容 div (#main) 后面的背景在 IE 7、8 和 9 中的内容之前停止外,在每个浏览器中一切都很好。我在末
我在 IE 11 中搜索过与 border-radius 相关的类似问题,但是 only one found on the Microsoft IE Developer site描述了自从“升级”到
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit th
这个问题在这里已经有了答案: (CSS?) Eliminating browser's 'selected' lines around a hyperlinked image? (5 个答案) 关闭
我知道有 1000 个问题,但我就是无法让它发挥作用。我只是想针对所有版本的 IE(包括 IE11)并给 html 一个特定的类,对于所有其他浏览器(firefox、opera、chrome),我希望
我有一个嵌入了 Internet Explorer 的程序。 在某些情况下,我需要调整嵌入式 IE 的缩放级别。我正在使用带有 OLECMDID_OPTICAL_ZOOM 的 ExecWB 命令来执行
我正在开发一个网络应用程序。我的应用程序在 chrome 和 firefox 上运行良好,但由于某种原因在 IE 中出现了一些错误。即使出现几个错误,应用程序仍然可以顺利运行,没有明显的问题。 我想对
我是一名优秀的程序员,十分优秀!