`
zxyskycn
  • 浏览: 50963 次
  • 性别: Icon_minigender_1
  • 来自: 天津
最近访客 更多访客>>
社区版块
存档分类
最新评论

兼容ff,ie的getStyle。关键字window.getComputedStyle(el, null)[style],el.currentStyle[sty

阅读更多
var getStyle=function(){     var f=document.defaultView;     return new Function('el','style',[         "style.indexOf('-')>-1 && (style=style.replace(/-(\\w)/g,function(m,a){return a.toUpperCase()}));",         "style=='float' && (style='",         f ? 'cssFloat' : 'styleFloat',         "');return el.style[style] || ",         f ? 'window.getComputedStyle(el, null)[style]' : 'el.currentStyle[style]',         ' || null;'].join('')); }();
 
 、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
 
 var getStyle=function(a,b){
   var isIE=document.all?true:false;
   if(isIE){
    try{
     return a.currentStyle[b];
    }catch(e){alert(e)}
   }else{
    return window.getComputedStyle(a,null)[b];
   }
  }

 

分享到:
评论

相关推荐

    js轮播图之旋转木马效果

    本文实例为大家分享了js轮播图之旋转木马效果的具体代码,供大家参考,具体内容如下 思路:给定一个数组,储存每张图片的位置,旋转将位置进行替换 ... window.getComputedStyle(element, null)[attr

    js仿360开机效果

    本文实例为大家分享了js仿360开机效果的具体代码,供大家参考,具体内容如下 实现效果: ...实现步骤: 1.封装运动函数 2.给图片上的关闭设置一个盒子 ...4.下面图片高度为0,... return window.getComputedStyle(obj, null

    window.js 主要包含了页面的一些操作

    代码如下://处理页面异常 function Exception() { } //页面元素共同接口 function View() { //页面元素 this.element = null; //文字颜色 this.color = null; //设置样式 this.setStyle = function(name, value) { ...

    数据源设置和动态Sql

    this.getStyle().backgroundColor = "red";//This would change all row instances onCreate: if (this.getRowData().getExpressionValue(3) > 100) this.getStyle().backgroundColor="red";//This will only ...

    原生JS实现风箱式demo,并封装了一个运动框架(实例代码)

    声明,该DEMO依托于某个培训机构中,非常感谢这个培训结构。话不多说,现在开始改demo的制作。 ... return window.getComputedStyle(obj,null)[attr];//为了获取W3C浏览器下的属性值 } } function

    animate.js

    window.getComputedStyle(element, null)[attr] : element.currentStyle[attr] || 0; } //动画函数 obj---要执行动画的对象 json---要执行到的目标的参数对象 fn为执行完成后的回调函数(可以再次调用此方法按照...

    js CSS操作方法集合

    //获取元素的真实的,最终的CSS样式属性值的函数 function getStyle(elem,name){ if(elem.style[name]){ return elem.style[name]; }else if(elem.currentStyle){ return elem.currentStyle[name]; }else if...

    Jquery作者John Resig自己封装的javascript 常用函数

    function getStyle(elem,name){ if(elem.style[name]){ return elem.style[name]; }else if(elem.currentStyle){ return elem.currentStyle[name]; }else if(document.defaultView&&document.defaultView....

    JavaScript常用兼容语法

    obj.currentStyle[attr]:getComputedStyle(obj)[attr]; } 2.事件event兼容写法 [removed] = function(e){ var e = e || window.event; } 3.事件监听的兼容写法 function bindEvent(dom,ev,fn){ if(dom.add

    JS.elementGetStyle(element, style)应用示例

    注: 获取Dom元素的Style数组中的指定Style元素 代码如下: function elementGetStyle(element, style) { var value = null; if (element.style) { value = element.style[style]; } if (!value) { if (document....

    手写的一个兼容各种浏览器的javascript getStyle函数(获取元素的样式)

    要想获取HTML元素的计算样式一直都存在很多的兼容问题,各浏览器都会存在一些差异,Firefox、webkit(Chrome,Safari)支持W3C标准的方法:getComputedStyle(),而IE6/7/8不支持标准的方法但是有私有的属性来实现:...

    JavaScript如何获取一个元素的样式信息

    if(elem.currentStyle){ return elem.currentStyle[cssprop] }else if(document.defaultView && document.defaultView.getComputedStyle){ return document.defaultView.getComputedStyle(elem, "")....

    IE及firefox下获取及设置样式值的代码

    } function getStyle(obj,styleName) { if(obj.currentStyle) //for ies { return obj.currentStyle[styleName]; //注意获取方式 } else //for others { return document.defaultView.getComputedStyle(obj,null)....

    javascript兼容性(实例讲解)

    1.事件冒泡: //取消冒泡 if(e.stopPropagation){ e.stopPropagation();//w3c定义的APIbiaozhun }else{ e.cancelBubble=true;... return element.currentStyle[stylename]; }else{ //其他浏览器

    dom.style:跨浏览器风格操作

    getStyle ( el , 'background-color' ) // => '#ffffff' , left = style . getNumericStyle ( el , 'left' ) // => [75, 'px'] , rotation = style . getStyle ( el , 'rotate' ) ; // => '45deg' style . ...

    js获取css的各种样式并且设置他们的方法

    js原生获取css样式,并且设置,看似简单,其实并不简单,我们平时用的ele.style.样式,只能获取内嵌的样式,但是我们写的样式基本都在style属性里面;... return getComputedStyle(element, null)[attr];  } } 平

    js获取页面引用的css样式表中的属性值方法(推荐)

    如下所示: function getStyle(node, property){... else if (node.currentStyle) { return node.currentStyle[property]; } else if (document.defaultView && document.defaultView.getComputedStyle) { var

    取非行间样式2

    IE6与其他浏览器兼容,取非行间样式2: function getStyle(obj, name) { if(obj.currentStyle) { return obj.currentStyle[name]; } else { return getComputedStyle(obj, false)[name]; } }

    javascript操作css属性

    obj.currentStyle[attribute] : document.defaultView.getComputedStyle(obj, false)[attribute];} 还有一种可以获取写在html中的style属性的 代码如下:document.getElementById(“elementId”).s

    Developing Flex Applications 910p dda_doc88_cracker.zip

    This package contains 3 kid: 1. a book Developing Flex Applications 2. a web page viewer for doc88 ebt ... CONTENTS PART I: Presenting Flex CHAPTER 1: Introducing Flex....About Flex....

Global site tag (gtag.js) - Google Analytics