--- the JS style property value acquisition element is calculated (the getComputedStyle) compatible functions ---

Computing style property acquired after acquisition ---- any one of a style property value element

 

Gets the value of an element from the left position

There will be compatibility problems as follows:
    . My $ ( "btn") onclick = function () {
       // get the value of the element from the left position 
      console.log (My $ ( "dv" ) .offsetLeft); 

      // Google, Firefox support 
      // console.log ( window.getComputedStyle (My $ ( "dv"), null) .left); 
      // console.log (window.getComputedStyle (My $ ( "dv"), null) [ "left"]); 

      // IE8 support 
      / / the console.log (My $ ( "DV") currentStyle.left.); 
    };

 

Gets the value of any element of any one style property

Thus a compatible package function, the browser determines whether the back support

// Get the value of any element of any one style property
  function the getStyle (Element, attr) {
       // determines whether the browser supports this approach 
      return window.getComputedStyle window.getComputedStyle (Element,? null ) [attr]: element.currentStyle [attr]; 
    }

 

test:

    //测试
    my$("btn").onclick = function () {
      console.log(getStyle(my$("dv"), "top"));
    };

 

 

Guess you like

Origin www.cnblogs.com/jane-panyiyun/p/12071285.html