html - Css Transform - Trigger event each time the mouse is out and in of a div -


i have 2 questions.

in project include code in post want:

  • the transform should trigger when hover on blue square.
  • the square should not return first position if mouse in red rectangle area or red square, when out of 2 divs.

i hope understand.

#square {      position: absolute;  	width:100px;  	height:100px;  	background-color:blue;  }    #rectangle {  	width:200px;  	height:100px;  	background-color:red;  }    #square:hover {      transform: translate(100px,0);      -webkit-transform: translate(100px,0); /** chrome & safari **/      -o-transform: translate(100px,0); /** opera **/      -moz-transform: translate(100px,0); /** firefox **/  }    .animation {      position: absolute;      transition: 2s ease-in-out;      -webkit-transition: 2s ease-in-out; /** chrome & safari **/      -moz-transition: 2s ease-in-out; /** firefox **/      -o-transition: 2s ease-in-out; /** opera **/  }
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">  <html xmlns="http://www.w3.org/1999/xhtml">  <head>  <meta http-equiv="content-type" content="text/html; charset=utf-8" />  <title> teste1 </title>  <link href="styles.css" rel="stylesheet" type="text/css">  </head>    <body>    <div id="rectangle" class="animation">    <div id="square" class="animation">  </div>    </div>    </body>  </html>

i use container blue square.
container event triggered, , @ init have same size square.
when hovered, size double fit on red rectangle.
way, animation indeed triggered square zone, , then, mouse detection performed on global rectangle.

the other tricky part reverse animation. when mouse leaving zone, use second animation on square container (longer one) keep largest zone still available if mouse red part. occurs when square getting original point.

so use css animation, available when mouse not on square container. hope following code speak itself.

note set background color of square container green, can see trick. has removed of course.

html

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title> teste1 </title> <link href="styles.css" rel="stylesheet" type="text/css"> </head>  <body>  <div id="rectangle" class="animation"> <div id="square-cont">    <div id="square" class="animation"> </div> </div>  </div>  </body> </html> 

css

#square {     position: absolute;     width:100px;     height:100px;     background-color:blue; } #square-cont {     width:100px;     height:100px;     background-color:green;     -webkit-transition: width 5s ease-in-out; /** chrome & safari **/     -o-transition: width 5s ease-in-out; /** opera **/     -moz-transition: width 5s ease-in-out; /** firefox **/ }  #rectangle {     width:200px;     height:100px;     background-color:red; }  #square-cont:hover #square {     transform: translate(100px,0);     -webkit-transform: translate(100px,0); /** chrome & safari **/     -o-transform: translate(100px,0); /** opera **/     -moz-transform: translate(100px,0); /** firefox **/ } #square-cont:hover{     width: 200px;      -webkit-transition: none; /** chrome & safari **/     -o-transition: none; /** opera **/     -moz-transition: none; /** firefox **/ }  .animation {     position: absolute;     transition: 2s ease-in-out;     -webkit-transition: 2s ease-in-out; /** chrome & safari **/     -moz-transition: 2s ease-in-out; /** firefox **/     -o-transition: 2s ease-in-out; /** opera **/ } 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -