在Javascript中設置位置時,我可以使用css'calc'函數嗎?我可以在JavaScript中使用CSS'calc'
ePopup.style.top =「calc(100px - 1.5em);」
在Javascript中設置位置時,我可以使用css'calc'函數嗎?我可以在JavaScript中使用CSS'calc'
ePopup.style.top =「calc(100px - 1.5em);」
是的,calc()
將在javascript中設置樣式時起作用。
工作實例:
var innerDiv = document.getElementsByClassName('inner-div')[0];
function growInnerDiv() {
innerDiv.style.width = 'calc(100% + 224px)';
}
innerDiv.addEventListener('click', growInnerDiv, false);
.outer-div {
display: inline-block;
width: 200px;
height: 100px;
padding: 12px;
border: 1px solid rgb(255,0,0);
background-color: rgb(255,255,0);
}
.inner-div {
width: 100px;
height: 100px;
color: rgb(255, 255, 255);
font-weight: bold;
text-align: center;
line-height: 100px;
font-family: arial, helvetica, sans-serif;
background-color: rgb(255,0,0);
cursor: pointer;
transition: all 0.5s linear;
}
<div class="outer-div">
<div class="inner-div">Click Me</div>
<div>
,如果你發佈前嘗試一下呢? – raven
我當然試過這個,它似乎沒有工作。它沒有工作,因爲我做了一些合成不正確的事情,或者因爲它本質上不起作用。 – NickC