2010-04-10 5 views
5

ben aracılığıyla onları alabilirsiniz:WebKit'te desteklenen tüm CSS özelliklerini nasıl alabilirim? Firefox, Opera ve IE yılında

>> for (k in document.body.style) console.log(k) 
-> cssText 
    length 
    parentRule 
    getPropertyValue 
    getPropertyCSSValue 
    removeProperty 
    getPropertyPriority 
    setProperty 
    item 
    getPropertyShorthand 
    isPropertyImplicit

Güncelleme: son WebKit does enumerate over CSS properties in HTMLElement.style aynı şekilde baştan WebKit olarak sonuçlar çok farklı oluyor

>> for (k in document.body.style) console.log(k) 
-> opacity 
    background 
    height 
    textAlign 
    . 
    ... long list ... 
    . 
    pointerEvents

tarayıcılar yapar.

cevap

6

cevabı onun solution Anton Byrna için

>> document.defaultView.getComputedStyle(document.body, '') 
-> CSSStyleDeclaration 
    0: "background-attachment" 
    1: "background-clip" 
    2: "background-color" 
    3: "background-image" 
    4: "background-origin" 
    5: "background-position" 
    6: "background-repeat" 
    7: "background-size" 
    8: "border-bottom-color" 
    9: "border-bottom-left-radius" 
    ...

teşekkürler olduğunu.


Bir problem hala kalır: getComputedStyle()background ve border gibi kısayolları döndürmez.

+0

'document.body.style' yinelemek Javascript stili özelliklerini sağlar. document.defaultView.getComputedStyle (document.body, '') 'sadece CSS özelliklerine sahiptir. Örneğin. "backgroundAttachment" ve "background-attachment". –

+0

'inherit', yüzde, text-bottom gibi olası tüm değerlerini elde etmenin herhangi bir yolu; her biri için. js kullanıyor olsa bile. –

1

Javascript erişimi hakkında emin değilim, ancak desteklenen tüm özellikleri (hatta mülk sahipleri) buraya bakabilirsiniz: CSS property names.

+4

CSS özellik adları için bağlantı http://trac.webkit.org/browser/trunk/Source/WebCore/css/CSSPropertyNames.in olarak değiştirildi –

+0

@Ghodmode Teşekkürler, cevabımı düzelttim. – fuxia