Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

pass js variable to css animation

document.querySelector('.p2').style.setProperty('--m','100%');
document.querySelector('.p2').style.setProperty('--w','300%');
.p1,.p2 {
  animation-duration: 3s;
  animation-name: slidein;
}

@keyframes slidein {
  from {
    margin-left: var(--m, 0%);
    width: var(--w, 100%);
  }
  to {
    margin-left: 0%;
    width: 100%;
  }
}
<p class="p1">
 This will not animate as the animation will use the default value set to the variable
</p>
<p class="p2">
  This will animate because we changed the CSS variable using JS
</p>
Comment

PREVIOUS NEXT
Code Example
Javascript :: invert binary tree js 
Javascript :: javascript array keyshort 
Javascript :: Log Time from Date 
Javascript :: check string length pixel "react" 
Javascript :: vscode react debug chrome profile 
Javascript :: get text 
Javascript :: discord.js const 
Javascript :: react native red Half Circle bubble 
Javascript :: antd table access data from object //with dot 
Javascript :: filter array and get index of num 
Javascript :: js plugin for drop down with images 
Javascript :: programmatically change mongoose schema enum values 
Javascript :: jquery auto idle logout 
Javascript :: jquery console.log object file 
Javascript :: Javacript code that delays, based on Milliseconds 
Javascript :: datatables show loading 
Javascript :: linked list distance between two nodes 
Javascript :: javascript replace char if not present another character 
Javascript :: lodash uniqBy alterantive in js 
Javascript :: javascript localstorage reference 
Javascript :: how to get file tree of specific folder in node js 
Javascript :: show dropdown upwards and downward 
Javascript :: gsheet function argument a1notation 
Javascript :: jquery: return true or false if the element is present in the DOM or not 
Javascript :: click to enlarge in javascript 
Javascript :: how to install ruchi js 
Javascript :: editable pre input react 
Javascript :: my env.local file not working in my react app usind mac 
Javascript :: ** in javascript 
Javascript :: React sub count 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =