jquery - 图像悬停动画

标签 jquery html css jquery-ui jquery-animate

我有以下 jQuery 脚本,它使橙色透明的悬停效果在鼠标滑过时覆盖图像。我该怎么做才能让这个脚本动画进出(淡入淡出?)

$(document).ready(function() {

    $('#gallery a').bind('mouseover', function(){
        $(this).parent('li').css({position:'relative'});
        var img = $(this).children('img');
        $('<div />').text(' ').css({
            'height': img.height(),
            'width': img.width(),
            'background-color': 'orange',
            'position': 'absolute',
            'top': 0,
            'left': 0,
            'opacity': 0.5
        }).bind('mouseout', function(){
            $(this).remove();
        }).insertAfter(this);
    });

});

最佳答案

尝试..

$(document).ready(function() {

    $('#gallery a').bind('mouseover', function(){
        $(this).parent('li').css({position:'relative'});
        var img = $(this).children('img');
        $('<div />').text(' ').css({
            'height': img.height(),
            'width': img.width(),
            'background-color': 'orange',
            'position': 'absolute',
            'top': 0,
            'left': 0,
            'opacity': 0.5
        }).bind('mouseout', function(){
            $(this).fadeOut(function(){ $(this).remove(); }); // <--- added fadeout()
        }).insertAfter(this).fadein(); //  <--- added fadeIn()
    });

});

关于jquery - 图像悬停动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3042977/

相关文章:

javascript - 捕获重定向下载链接的 HTTP 状态 300

jQuery .autocomplete() 在一个输入字段中包含邮政编码和城市名称

html - 使用 CSS 代替 <strong/> HTML 标签

html - 在html中调整div

javascript - 同位素转换 'flash' 错误(Chrome)

javascript - jQuery 在单击的选项卡上添加类并在没有时删除

html - 尝试让我的文本始终具有相同的宽度,即使我的 div 有更多可用空间

html - 水平布局图像和段落

html - IE 7 将我的水平导航栏变成双线

php - 完成后使用 jQuery 向 iframe 反馈提交表单?