fadeOut/fadeIn image over element

这一生的挚爱 提交于 2019-12-12 02:18:50

问题


I currently have a div with a image overlaid that I am currently using the following code to fadeout the image to show the text in the element underneath:

$(".Content_Frame_Image").hover(
function() {
$(this).stop().animate({"opacity": "0"}, "slow");
},
function() {
$(this).stop().animate({"opacity": "1"}, "slow");
});

However because im only making it invisible I cant get the links to work underneath, you can see a sample here http://playing.everythingcreative.co.uk

If I use the fadeout method then it wont fadein on hover...


回答1:


what's about:

$(".Content_Frame_Container")
    .each(function(){
        $(this).find('.Content_Frame_Image');
    })
    .hover( 
        function(){
            $(this).find('.Content_Frame_Image').stop().fadeOut('slow');
        }, 
        function(){
            $(this).find('.Content_Frame_Image').stop().fadeIn('slow');
        }
    );

tested it with chrome dev-tools -- should work nicely.




回答2:


If you need to use opacity instead of fadeOut, a callback function after your animation:

$(".Content_Frame_Image").hover(
function() {
    $(this).stop().animate({"opacity": "0"}, "slow", function() {
        //move the element off-screen
        $(this).css({
            'position' : 'absolute',
            'left' : '-9999px'
        });
    });
},
function() {
    //move it back first
    $(this).css({
        'position' : 'absolute',
        'left' : '0'
    });
    $(this).stop().animate({"opacity": "1"}, "slow");
});


来源:https://stackoverflow.com/questions/12148702/fadeout-fadein-image-over-element

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