Javascript DOM CSS Style transitionTimingFunction Property

Introduction

Change the speed curve of a transition effect:

document.getElementById("myDIV").style.transitionTimingFunction = "linear";

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {//from  www  .  j  av a  2  s  . c o m
  border: 1px solid black;
  background-color: lightblue;
  width: 270px;
  height: 200px;
  overflow: auto;
  transition: all 2s;
}

#myDIV:hover {
  background-color: coral;
  width: 570px;
  height: 500px;
  padding: 100px;
  border-radius: 50px;
}
</style>
</head>
<body>

<p>Mouse over the DIV element and it will change, gradually, both in color and size!</p>

<button onclick="myFunction()">Test</button>

<div id="myDIV">
  <h1>myDIV</h1>
</div>

<script>
function myFunction() {
  document.getElementById("myDIV").style.transitionTimingFunction = "linear";
}
</script>

</body>
</html>

The transitionTimingFunction property specifies the speed curve of the transition effect.

This property allows a transition effect to change speed over its duration.

Property Values

Value
Description
ease
Default. a transition effect with a slow start, then fast, then end slowly
linear
a transition effect with the same speed from start to end
ease-in
a transition effect with a slow start
ease-out
a transition effect with a slow end
ease-in-out
a transition effect with a slow start and end
cubic-bezier(n, n, n, n)

Define your own values in the cubic-bezier function.
Possible values are numeric values from 0 to 1
initial
Sets this property to its default value.
inherit
Inherits this property from its parent element.

The transitionTimingFunction property returns a String representing the transition-timing-function property of an element.




PreviousNext

Related