2011-08-23 85 views
2

是否可以動態設置僞元素的CSS?例如:動態使用JavaScript的僞元素CSS

jQuery的動態造型幫助容器

$('#help').css({ 
    "width" : windowWidth - xOffset, 
    "height" : windowHeight - yOffset, 
    "bottom" : -windowHeight, 
    "left" : 200 
}); 

jQuery的嘗試在設置幫助容器的內邊框:

$('#help:before').css({ 
    "width" : windowWidth - xOffset, 
    "height" : windowHeight - yOffset 
}); 

CSS文件上面

#help 
{ 
    opacity: 0.9; 
    filter:alpha(opacity=90); 
    -moz-opacity: 0.9;   
    z-index: 1000000; 
    bottom: -550px; 
    left: 400px; 
    background-color: #808080; 
    border: 5px dashed #494949; 
    -webkit-border-radius: 20px 20px 20px 20px; 
    -moz-border-radius: 20px 20px 20px 20px; 
    border-radius: 20px 20px 20px 20px;   
} 
#help:before 
{ 
    border: 5px solid white; 
    content: ''; 
    position: absolute; 
    -webkit-border-radius: 20px 20px 20px 20px; 
    -moz-border-radius: 20px 20px 20px 20px; 
    border-radius: 20px 20px 20px 20px;   
} 
+0

可能重複的[設置CSS僞類規則從JavaScript](http://stackoverflow.com/questions/311052/setting-css-pseudo-class-rules-from-javascript) – thirtydot

回答

0

而不是使用.css()設置寬度和高度,您應該直接使用.width()height()

+1

您可以發佈代碼爲此,我的代碼不起作用: $('#help:before')。width(windowHeight - 410) .height(windowHeight - 210); – Jack