transition



значения свойства:


  • transition-property
  • transition-duration



css/style.css
  • * {
  •  margin: 0;
  •  padding: 0;
  • }
  •  
  • .main {
  •  height: 600px;
  •  width: 900px;
  •  position: absolute;
  •  top: 50%;
  •  left: 50%;
  •  margin-top: -300px;
  •  margin-left: -450px;
  • }
  •  
  • .wrapper {
  •  width: 33.3%;
  •  height: 100%;
  •  float: left;
  • }
  •  
  • #div1, #div2, #div3 {
  •  height: 200px;
  •  width: 200px;
  •  float: left;
  •  position: relative;
  •  top: 50%;
  •  left: 50%;
  •  margin-top: -100px;
  •  margin-left: -100px;
  •  background-color: #3BA9DE;
  • }
  •  
  • #div1 {
  •  transition: width, height, background-color, 1s;
  •  -moz-transition: width, height, background-color, 1s;
  •  -o-transition: width, height, background-color, 1s;
  •  -webkit-transition: width, height, background-color, 1s;
  •  -ms-transition: width, height, background-color, 1s;
  • }
  •  
  • #div2 {
  •  -moz-transition: height, background-color, 1s;
  •  -o-transition: height, background-color, 1s;
  •  -webkit-transition: height, background-color, 1s;
  • }
  •  
  • #div1:hover {
  •  width: 250px;
  •  height: 250px;
  •  background-color: #A3E61D;
  • }
  •  
  •  
  • #div2:hover {
  •  height: 250px;
  •  background-color: #7092BE;
  • }
  •  
  • #div3:hover {
  •  width: 250px;
  •  background-color: #852E76;
  • }
* {
 margin: 0;
 padding: 0;
}

.main {
 height: 600px;
 width: 900px;
 position: absolute;
 top: 50%;
 left: 50%;
 margin-top: -300px;
 margin-left: -450px;
}

.wrapper {
 width: 33.3%;
 height: 100%;
 float: left;
}

#div1, #div2, #div3 {
 height: 200px;
 width: 200px;
 float: left;
 position: relative;
 top: 50%;
 left: 50%;
 margin-top: -100px;
 margin-left: -100px;
 background-color: #3BA9DE;
} 

#div1 {
 transition: width, height, background-color, 1s;
 -moz-transition: width, height, background-color, 1s;
 -o-transition: width, height, background-color, 1s;
 -webkit-transition: width, height, background-color, 1s;
 -ms-transition: width, height, background-color, 1s;
}

#div2 {
 -moz-transition: height, background-color, 1s;
 -o-transition: height, background-color, 1s;
 -webkit-transition: height, background-color, 1s;
}

#div1:hover {
 width: 250px;
 height: 250px;
 background-color: #A3E61D;
}


#div2:hover {
 height: 250px;
 background-color: #7092BE;
}

#div3:hover {
 width: 250px;
 background-color: #852E76;
}


index.html
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <link href="css/style.css" rel="stylesheet" />
  •  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  • </head>
  • <body>
  •  <div class="main">
  •   <div class="wrapper">
  •    <div id="div1"></div>
  •   </div>
  •   <div class="wrapper">
  •    <div id="div2"></div>
  •   </div>
  •   <div class="wrapper">
  •    <div id="div3"></div>
  •   </div>
  •  </div>
  •  <script>
  •   /*JavaScript*/
  •   document.getElementById("div2").style.transition="height, background-color, 1s";
  •   document.getElementById("div2").style.msTransition="height, background-color, 1s";
  •   /*jQuery*/
  •   $(document).ready(function() {
  •    $("#div3").css({ "transition": "width, background-color, 1s" });
  •    $("#div3").css({ "-moz-transition": "width, background-color, 1s" });
  •    $("#div3").css({ "-o-transition": "width, background-color, 1s" });
  •    $("#div3").css({ "-webkit-transition": "width, background-color, 1s" });
  •    $("#div3").css({ "-ms-transition": "width, background-color, 1s" });
  •   });
  •  </script>
  • </body>
  • </html>
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <link href="css/style.css" rel="stylesheet" />
  •  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  • </head>
  • <body>
  •  <div class="main">
  •   <div class="wrapper">
  •    <div id="div1"></div>
  •   </div>
  •   <div class="wrapper">
  •    <div id="div2"></div>
  •   </div>
  •   <div class="wrapper">
  •    <div id="div3"></div>
  •   </div>
  •  </div>
  •  <script>
  •   /*JavaScript*/
  •   document.getElementById("div2").style.transition="height, background-color, 1s";
  •   document.getElementById("div2").style.msTransition="height, background-color, 1s";
  •   /*jQuery*/
  •   $(document).ready(function() {
  •    $("#div3").css({ "transition": "width, background-color, 1s" });
  •    $("#div3").css({ "-moz-transition": "width, background-color, 1s" });
  •    $("#div3").css({ "-o-transition": "width, background-color, 1s" });
  •    $("#div3").css({ "-webkit-transition": "width, background-color, 1s" });
  •    $("#div3").css({ "-ms-transition": "width, background-color, 1s" });
  •   });
  •  </script>
  • </body>
  • </html>