SlideShare une entreprise Scribd logo
1  sur  13
Télécharger pour lire hors ligne
스타일 객체 활용Feb 26, 2015 - 이준호
스타일 객체???
http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113
next   contents   index
Document Object Model (DOM) Level 2 Style Specification
Version 1.0
W3C Recommendation 13 November, 2000
This version:
http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113
( PostScript file , PDF file , plain text , ZIP file)
Latest version:
http://www.w3.org/TR/DOM-Level-2-Style
Previous version:
http://www.w3.org/TR/2000/PR-DOM-Level-2-Style-20000927
스타일 객체??
CSSStyleDeclaration
Overview  Package   Class  Tree  Index  Help 
 PREV CLASS   NEXT CLASS
SUMMARY:  INNER | FIELD | CONSTR |  METHOD DETAIL:  FIELD | CONSTR | METHOD
org.w3c.dom.css
Interface CSSStyleDeclaration
public interface CSSStyleDeclaration
The CSSStyleDeclaration interface represents a single CSS declaration block. This interface may be used to determine the
style properties currently set in a block or to set style properties explicitly within the block.
While an implementation may not recognize all CSS properties within a CSS declaration block, it is expected to provide
access to all specified properties in the style sheet through the CSSStyleDeclaration interface. Furthermore, implementations
that support a specific level of CSS should correctly handle CSS shorthand properties for that level. For a further
discussion of shorthand properties, see the CSS2Properties interface.
This interface is also used to provide a read-only access to the computed values of an element. See also the ViewCSS
interface.
Note: The CSS Object Model doesn't provide an access to the specified or actual values of the CSS cascade.
DOM
DOCUMENT
OBJECT
MODEL
스타일 객체?
CSSStyleDeclaration
document.createElement('div').style
최종적으로 모든 스타일의 정보가 저장되는 객체
MSStyleCSSProperties, CSS2Properties
CSSStyleDeclaration
document.getElementById('console').innerHTML = '' +
document.getElementsByTagName('head')[0].style + '<br>' +
document.getElementsByTagName('html')[0].style + '<br>' +
document.createElement('script').style + '<br>' +
document.createElement('link').style + '<br>';
CSSStyleDeclaration 활용
var div_test = document.getElementById('div_test');
div_test.style.left = '100px';
...
<style></style>, <link></link>
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d');
context.fillStyle = 'red';
context.fillRect( 0, 0, 100, 100 );
// document.createElement('style').style
// canvas의 context를 얻어와 제어하는 것처럼..
// canvas라는 태그는 실제 동작하는 context를 HTML 문서에 부착하기 위한 공통 인터페이스로 이해할 수 있음.
// style 엘리먼트의 style 객체를 제어하는 것이 아닌.
// style 엘리먼트에 있는 실제 스타일 시트 객체를 얻어와야 한다.
스타일 객체( CSSStyleDeclaration )를 찾아서.
console.dir(document.getElementById('style_test'))
console.dir(document.getElementById('style_test').sheet)
console.dir(document.getElementById('style_test').sheet.cssRules)
console.dir(document.getElementById('style_test').sheet.cssRules[0])
console.dir(document.getElementById('style_test').sheet.cssRules[0].style)
정리하면
Browser CSSStyleDeclaration CSSStyleSheet CSSRuleList
IE MSStyleCSSProperties sheet, styleSheet cssRules, rules
Chrome CSSStyleDeclaration sheet cssRules, rules
FireFox CSS2Properties sheet cssRules
Safari CSSStyleDeclaration sheet cssRules, rules
selectorText, style
추가, 제거
var styleEl = document.createElement('style');
document.getElementsByTagName('head')[0].appendChild(styleEl);
var sheet = styleEl.sheet || styleEl.styleSheet;
var rules = sheet.cssRules || sheet.rules;
sheet.insertRule( 'p{}', 0 ); // sheet.addRule( 'p', ' ' );
var rule = rules[0];
rule.style['color'] = 'red';
sheet.deleteRule(0); // sheet.removeRule(0);
This is Test
결론
최종적으로 스타일 속성을 저장하고 제어의 대상이 되는 것은 CSSStyleDelaration 객체
모든 DOM Element에는 style 속성이 있음. ( CSSStyleDelaration )
스타일 시트 또한 CSSRule 객체에 style 속성이 있음.
따라서 스타일시트 또한 얼마든지 제어가 가능.
스타일시트의 CSSRuleList를 제어하게 되면..
런타임에 동적으로 스타일 시트를 변경할 수 있게 되고.
풍부한 프로그래밍 언어로서의 자바스크립트로 스타일 시트를 통제할 수 있음.
인라인이 아니라 스타일 시트에 지정한 스타일이 되므로
스타일시트의 성능과 하드웨어의 도움 등을 그대로 활용 가능.
THANK YOU
http://ligo.kr/akj

Contenu connexe

En vedette

夏サミ2013 Hadoopを使わない独自の分散処理環境の構築とその運用
夏サミ2013 Hadoopを使わない独自の分散処理環境の構築とその運用夏サミ2013 Hadoopを使わない独自の分散処理環境の構築とその運用
夏サミ2013 Hadoopを使わない独自の分散処理環境の構築とその運用Developers Summit
 
Ошибки руководства интернет-компании в управлении командой, и можно ли как и...
Ошибки руководства интернет-компании в управлении командой,  и можно ли как и...Ошибки руководства интернет-компании в управлении командой,  и можно ли как и...
Ошибки руководства интернет-компании в управлении командой, и можно ли как и...Fert
 
Dos and donts of social media for educators 20150529
Dos and donts of social media for educators 20150529Dos and donts of social media for educators 20150529
Dos and donts of social media for educators 20150529dinica
 
[HQ Nacional] Street Fighter II Ano I - Número 1 - parte 2
[HQ Nacional] Street Fighter II   Ano I - Número 1 - parte 2[HQ Nacional] Street Fighter II   Ano I - Número 1 - parte 2
[HQ Nacional] Street Fighter II Ano I - Número 1 - parte 2Santuário do Mestre Ryu
 
Master paleodieta crossfit redwall cus ferrara 26 10-2014
Master paleodieta crossfit redwall cus ferrara 26 10-2014 Master paleodieta crossfit redwall cus ferrara 26 10-2014
Master paleodieta crossfit redwall cus ferrara 26 10-2014 GJAV
 
Trip of a Lifetime: Spring 2011
Trip of a Lifetime: Spring 2011Trip of a Lifetime: Spring 2011
Trip of a Lifetime: Spring 2011Trip of a Lifetime
 
Neoea summer academy 2013
Neoea summer academy 2013Neoea summer academy 2013
Neoea summer academy 2013dinica
 
Bouyn Brochurev1
Bouyn Brochurev1Bouyn Brochurev1
Bouyn Brochurev1allanedun
 
Perspectives on ideology
Perspectives on ideologyPerspectives on ideology
Perspectives on ideologyhmoulds
 

En vedette (18)

夏サミ2013 Hadoopを使わない独自の分散処理環境の構築とその運用
夏サミ2013 Hadoopを使わない独自の分散処理環境の構築とその運用夏サミ2013 Hadoopを使わない独自の分散処理環境の構築とその運用
夏サミ2013 Hadoopを使わない独自の分散処理環境の構築とその運用
 
Mfc
MfcMfc
Mfc
 
Ошибки руководства интернет-компании в управлении командой, и можно ли как и...
Ошибки руководства интернет-компании в управлении командой,  и можно ли как и...Ошибки руководства интернет-компании в управлении командой,  и можно ли как и...
Ошибки руководства интернет-компании в управлении командой, и можно ли как и...
 
Dos and donts of social media for educators 20150529
Dos and donts of social media for educators 20150529Dos and donts of social media for educators 20150529
Dos and donts of social media for educators 20150529
 
Review2015
Review2015Review2015
Review2015
 
[HQ Nacional] Street Fighter II Ano I - Número 1 - parte 2
[HQ Nacional] Street Fighter II   Ano I - Número 1 - parte 2[HQ Nacional] Street Fighter II   Ano I - Número 1 - parte 2
[HQ Nacional] Street Fighter II Ano I - Número 1 - parte 2
 
Globalinvacom
GlobalinvacomGlobalinvacom
Globalinvacom
 
Master paleodieta crossfit redwall cus ferrara 26 10-2014
Master paleodieta crossfit redwall cus ferrara 26 10-2014 Master paleodieta crossfit redwall cus ferrara 26 10-2014
Master paleodieta crossfit redwall cus ferrara 26 10-2014
 
Noticias Teleco feb2011
Noticias Teleco feb2011Noticias Teleco feb2011
Noticias Teleco feb2011
 
Trip of a Lifetime: Spring 2011
Trip of a Lifetime: Spring 2011Trip of a Lifetime: Spring 2011
Trip of a Lifetime: Spring 2011
 
Neoea summer academy 2013
Neoea summer academy 2013Neoea summer academy 2013
Neoea summer academy 2013
 
Installing vpn client
Installing vpn clientInstalling vpn client
Installing vpn client
 
Bouyn Brochurev1
Bouyn Brochurev1Bouyn Brochurev1
Bouyn Brochurev1
 
Perspectives on ideology
Perspectives on ideologyPerspectives on ideology
Perspectives on ideology
 
NVN7125, berekenen energiebesparende gebiedsmaatregelen
NVN7125, berekenen energiebesparende gebiedsmaatregelenNVN7125, berekenen energiebesparende gebiedsmaatregelen
NVN7125, berekenen energiebesparende gebiedsmaatregelen
 
Na 7 jaar frisse scholen...
Na 7 jaar frisse scholen...Na 7 jaar frisse scholen...
Na 7 jaar frisse scholen...
 
Energiebesparing met prestatiecontracten
Energiebesparing met prestatiecontractenEnergiebesparing met prestatiecontracten
Energiebesparing met prestatiecontracten
 
20160910 fabcrossクラウドファンドイベント
20160910 fabcrossクラウドファンドイベント20160910 fabcrossクラウドファンドイベント
20160910 fabcrossクラウドファンドイベント
 

Plus de Jun Ho Lee

우아한오픈소스
우아한오픈소스우아한오픈소스
우아한오픈소스Jun Ho Lee
 
ECMA2015 INSIDE
ECMA2015 INSIDEECMA2015 INSIDE
ECMA2015 INSIDEJun Ho Lee
 
HTML5 관점에서 본 2015년 웹개발 트렌드 및 인사이트
HTML5 관점에서 본 2015년 웹개발 트렌드 및 인사이트HTML5 관점에서 본 2015년 웹개발 트렌드 및 인사이트
HTML5 관점에서 본 2015년 웹개발 트렌드 및 인사이트Jun Ho Lee
 
WebGL 20150428
WebGL 20150428WebGL 20150428
WebGL 20150428Jun Ho Lee
 
WebGL 20150406
WebGL 20150406WebGL 20150406
WebGL 20150406Jun Ho Lee
 
지금까지 상상한 Web 표현의한계를넘자 WebGL
지금까지 상상한 Web 표현의한계를넘자 WebGL지금까지 상상한 Web 표현의한계를넘자 WebGL
지금까지 상상한 Web 표현의한계를넘자 WebGLJun Ho Lee
 
WebGL의 무궁무진한 가능성
WebGL의 무궁무진한 가능성 WebGL의 무궁무진한 가능성
WebGL의 무궁무진한 가능성 Jun Ho Lee
 

Plus de Jun Ho Lee (7)

우아한오픈소스
우아한오픈소스우아한오픈소스
우아한오픈소스
 
ECMA2015 INSIDE
ECMA2015 INSIDEECMA2015 INSIDE
ECMA2015 INSIDE
 
HTML5 관점에서 본 2015년 웹개발 트렌드 및 인사이트
HTML5 관점에서 본 2015년 웹개발 트렌드 및 인사이트HTML5 관점에서 본 2015년 웹개발 트렌드 및 인사이트
HTML5 관점에서 본 2015년 웹개발 트렌드 및 인사이트
 
WebGL 20150428
WebGL 20150428WebGL 20150428
WebGL 20150428
 
WebGL 20150406
WebGL 20150406WebGL 20150406
WebGL 20150406
 
지금까지 상상한 Web 표현의한계를넘자 WebGL
지금까지 상상한 Web 표현의한계를넘자 WebGL지금까지 상상한 Web 표현의한계를넘자 WebGL
지금까지 상상한 Web 표현의한계를넘자 WebGL
 
WebGL의 무궁무진한 가능성
WebGL의 무궁무진한 가능성 WebGL의 무궁무진한 가능성
WebGL의 무궁무진한 가능성
 

스타일 객체 활용