당신은이 효과를 할 자바 스크립트를 필요로하지 않는 작업 데모 http://jsfiddle.net/pomeh/U4dyE/입니다 코드 :
HTML 코드
<div id="container">
<div class="wrap">
<div class="box"></div>
<div class="box"></div>
</div>
</div>
CSS 코드
,369보고
#container {
width: 300px;
height: 300px;
}
/* DRY :) */
.wrap, .box {
width: 50px;
height: 50px;
float: left;
margin: 1px 1px 1px 1px;
}
.box {
background-color: red;
opacity: 1;
filter:alpha(opacity=100);
/* animation for "mouse out" */
-webkit-transition: opacity 0.5s linear; /* Saf3.2+, Chrome */
-moz-transition: opacity 0.5s linear; /* FF4+ */
-ms-transition: opacity 0.5s linear; /* IE10 */
-o-transition: opacity 0.5s linear; /* Opera 10.5+ */
transition: opacity 0.5s linear;
}
.box:hover {
opacity: 0.5;
filter:alpha(opacity=50);
/* animation for "mouse in" */
-webkit-transition: opacity 0.5s linear; /* Saf3.2+, Chrome */
-moz-transition: opacity 0.5s linear; /* FF4+ */
-ms-transition: opacity 0.5s linear; /* IE10 */
-o-transition: opacity 0.5s linear; /* Opera 10.5+ */
transition: opacity 0.5s linear;
}
JS 코드
// absolutely none ! :)
왜 대신 CSS를 사용하지? 아래 내 대답을 확인하십시오 :) – pomeh
@ pomeh JQuery를 배워야하기 때문에 – Paul
글쎄,이 경우에는 자바 스크립트 (및 jQuery)가 필요한 경우와 그렇지 않은 경우를 배워야합니다. 여기, 그것은 전혀 필요하지 않습니다. 그리고 CSS 솔루션은 Javascript보다 더 나은 성능을 발휘할 것입니다. :) BTW,'jQuery'라고 쓰여 있습니다 :) – pomeh