JavaScript 현재 스타일 가 져 오기

523 단어 자바 script
sss

외부 스타일 파일 1.css 사용 하기:
*{
    margin: 0;
    padding: 0;
}


.box{
    width: 320px;
    background: #f00;
    transform:translateX(30px);
}

JS 현재 스타일 가 져 오 는 방법:
let getStyle = function(tag,prop){
    return tag.currentStyle? tag.currentStyle[prop] : getComputedStyle(tag)[prop] ;
};

let box = document.getElementById("box");
console.info( getStyle(box,"width"));   // 320px

좋은 웹페이지 즐겨찾기