2014-07-10 2 views
0

높이를 루트 요소로 설정했는지 아닌지를 감지하는 모듈에 생각을 추가하려면 (웹 구성 요소로 생각하십시오), 그렇지 않은 경우 높이를 계산합니다 요인.요소에 선언 된 값이 있는지 확인하십시오.

이 모듈에는 절대 위치 지정 및 기타 '멋진'정보가있어 정상적인 흐름이 문제가되지 않습니다.

내가 document.styleSheets 통해 반복하고 각 cssRule 다음 cssText를 분석하거나 style 객체 내부의 '높이'의 비어 있지 않은 키를 찾으의 selectorText에 루트 요소의 ID 또는 클래스에 대한 검사의 생각했다.

더 나은 (또는 표준) 방법이 있습니까?

PS - 질문을 공식화하면서 난 그냥 그것을 해결했을 수 있습니다, 그래서 당신은 동일한 문제로 실행하는 경우 - 여기에 나중에 가자!

+0

defaultValue 속성을 사용해 보셨습니까? – Pikamander2

+0

defaultValue? 어떤? – tripleZee

답변

0

여기에 꽤 원유 구현의 :

isHeightSet: function() { 
    var id = this.elements.root.id, 
     _isHeightSet = false; // the crude part ;-) 

    // go through stylesheets 
    _.each(document.styleSheets, function(styleSheet) { 

     // go through rules 
     _.each(styleSheet.cssRules, function(cssRule) { 

      // if selectorText contains our id 
      if (cssRule.selectorText && cssRule.selectorText.indexOf(id) !== -1) { 

       // check if the height is set 
       if (cssRule.style.height && 
        (cssRule.style.height !== 'auto' && 
        cssRule.style.height !== 'inherit')) { 

        // keep on hacking! 
        _isHeightSet = true; 
       } 
      } 
     }); 
    }); 

    return _isHeightSet; 
} 

아마 더 강력한 될 수 있지만, 잘 작동하는 것 같다.

관련 문제