fade in/out with css3 [duplicate]

孤街醉人 提交于 2019-12-04 11:22:04

问题


Possible Duplicate:
thumbnails fade in fade out

I'm curios if it's possible to achieve this effect ( only the fade in/out )

with css3. I have a similar thumbnails scroller and I want to create that effect without javascript, or if this is not possible could you help me with a simple solution for creating this with jquery ? Thanks!


回答1:


Yes this is possible with CSS3 transitions.

Here's an example: http://jsfiddle.net/fgasU/

code:

<img src="photo.jpg"/>​

img{-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
-ms-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}


img:hover{opacity:0}​

This simple example will change the opacity on hover. Because a css transition is defined for 'all' properties, and they are given a 1 second transition with an ease-in-out easing function, the property change is animated.

Also, because it is a new property, the transition property must be preceded by the applicable brower's implementation. -webkit for chrome/safari, -moz for firefox/mozilla, -o opera, -ms microsoft.




回答2:


The jQuery solution: Wrap the thumbnails in a trigger div, which is absolutely positioned over the image. Target that to fade the elements in and out.

For a CSS3 solution, refer to Vigrond's answer.

HTML

<div id="wrapper">
    <img src="http://lorempixum.com/600/600" />
    <div id="trigger">
        <div id="thumbnails">
             <img src="http://lorempixum.com/60/60" />
             <img src="http://lorempixum.com/60/60" /> 
             <img src="http://lorempixum.com/60/60" /> 
             <img src="http://lorempixum.com/60/60" /> 
        </div>
    </div>
</div>

CSS

#wrapper { position:relative; }

#trigger {
    width:100%;
    height:80px;
    position:absolute;
    left:0;
    bottom:20px; }

#thumbnails {
    width:100%;
    height:80px;
    display:none; }

#thumbnails img {
    margin:10px;
    float:left; }

jQuery

$(document).ready(function(){
    $("#trigger").hover(function () {
       $(this).children("div").fadeTo(200, 1);
    }, function(){
         $(this).children("div").fadeOut(200); 
    });
});

See my fiddle: http://jsfiddle.net/TheNix/Cjmr6/



来源:https://stackoverflow.com/questions/9250619/fade-in-out-with-css3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!