2012-04-18 3 views
1

브라우저에서 특정 CSS 속성 속성이 지원되는지 테스트하고 싶습니다. CSS 속성에 대해 내가 할 수있는 것처럼CSS 속성 속성에 대한 지원 확인

document.createElement("detect").style["-webkit-overflow-scrolling"] === "" 

하지만 특정 클래스 또는 속성을 확인해야하는 경우 어떻게해야합니까? 예를 들어,

position:fixed 

에 대한 지원을 테스트하고 싶습니다. (Modernizr을 제외하고) 어떻게 할 수 있습니까? Pls 도움.

답변

1
function isFixedSupported() { 
    var isSupported = null; 
    if (document.createElement) { 
     var el = document.createElement("div"); 
     if (el && el.style) { 
      el.style.position = "fixed"; 
      el.style.top = "10px"; 
      var root = document.body; 
      if (root && root.appendChild && root.removeChild) { 
       root.appendChild(el); 
       isSupported = el.offsetTop === 10; 
       root.removeChild(el); 
      } 
     } 
    } 
    return isSupported; 
} 

var canUseFixed = isFixedSupported(); //true:false 

FIDDLE

+0

당신 수 http://kangax.github.com/cft/#IS_POSITION_FIXED_SUPPORTED –

+0

나는 오랫동안이 사용하고 어디에 정확히 기억하지 적어도 링크 I 처음에는 알았지 만, 아마도이 사이트가 여기에 있다고 생각하지 않습니다. 아마도이 기능이있는 다른 백 사이트 중 하나 일 것입니다. 바로 여기에 약간의 검색을 한 것 같습니다. [Stack Overflow] (http://stackoverflow.com/questions)/3911866/how-to-detect-lack-of-position-fixed-in-a-generic-way). Kangax에서 시작된 것이라면, 나는 모른다. 아마도? – adeneo

+0

My bad then :-) –