Last active
November 14, 2018 04:52
-
-
Save speir-wang/796897746e423259b71d0da10f9005d5 to your computer and use it in GitHub Desktop.
Change pseudo element properties with JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SCSS | |
.element { | |
--dynamic-width: 0%; | |
width: 200px; | |
height: 200px; | |
background-color: #ccc; | |
margin: 0 auto; | |
&:after { | |
content: ""; | |
display: block; | |
background-color: #000; | |
height: 2px; | |
width: var(--dynamic-width); | |
position:relative; | |
left: 100%; | |
top: 50%; | |
transition: width 0.2s ease; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JavaScript | |
let element = document.getElementsByClassName("element")[0]; | |
element.style.setProperty("--dynamic-width", '50%'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment