Fading one div into another: Make more stable, remove white pause, multiple fades

谁说我不能喝 提交于 2019-12-05 14:23:19

1) Rather than do the fadeIn of the hover item on the callback, do it immediately. This will prevent the white background showing through:

$('.grid-box .phase-1').fadeOut(300);
$('.grid-box .phase-2').fadeIn(300);

2) The easiest way to do this is to specify a size on the thumbnail container and the add overflow: hidden; to it.

3) Finally the following code will make sure only the elements contained within the hovered-over div will be affected:

$(function(){
    $('.grid-box').hover(
        function(){
            $('.phase-1', this).fadeOut(300);
            $('.phase-2', this).fadeIn(300);
        },
        function(){
            $('.phase-2', this).fadeOut(300)
            $('.phase-1', this).fadeIn(300);
        }
    ); 
});

HTML

<div class="grid-box">
    <div class="phase-1"></div>
    <div class="phase-2"></div>
</div>

JQ

$(document).click(function (){
$('.grid-box .phase-1').animate({opacity:50},2000).queue(function(){
     $(this).hide();

});
$('.grid-box .phase-2').fadeIn(2000);
});

CSS

.phase-1{width: 100px;height: 100px;background: red; position:absolute;}
.phase-2{width: 100px;height: 100px;background: blue;display: none; position:absolute;}

I know this isn't exactly how your code looks like but you can see what I mean in a simple explaination.

here is a demo of it in jsfiddle http://jsfiddle.net/NxJf8/

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