jquery - 将鼠标悬停事件添加到砌体

标签 jquery css mouseover jquery-masonry

这可能是一个简单的答案,但我很难找到它。

我正在使用 masonry 插件用图像填充页面。图片是艺术品。当您将鼠标悬停在他/她的作品图像上时,我希望艺术家的名字从底部向上滑动。

现在我只是想让鼠标悬停事件起作用,但什么也没有发生。请问有人可以帮忙吗?

$(document).ready(function(){


$.get("artists.json", function(data){

    json = $.parseJSON(data);

    $.each(json, function(i, data){

            $("#container").append("<div class='thumbnail small' id='" + data.id + "' index='"+i+"' style=\"background:url('" + data.imageofWork + "') no-repeat center center; background-size:cover; \" caption = '"+data.artistName+"' ></div>");



    });

});

$("#container").imagesLoaded( function(){
    setTimeout(function()
    {
        $('#container').masonry({
            itemSelector : '.thumbnail',
            gutterWidth: 0,
            isAnimated: true
        });

        $("#container").css('visibility','visible').hide().fadeIn('slow', function(){setTimeout(function(){ checkURL();},500)});

    },1200)



});


$(document).on("mouseover", ".thumbnail.small", function(){

        //console.log($(this));
        $(this).css('width:', '110%');
});

最佳答案

你可以用 css 做到这一点......

http://jsfiddle.net/3Rkdp/1/

你的 jquery(来自你的回答)

$("#container").append("<div class='thumbnail small' id='" + data.id + "' index='"+i+"' style=\"background:url('" + data.imageofWork + "') no-repeat center center; background-size:cover; \" ><div id='artistname' style='display: block; visibility: hidden;z-index:1000; font-size: 115%; font-weight: bold; padding: 10px; background-color: #000000; color: #ffffff; opacity: .5;'>"+data.artistName+"</div></div>");

CSS

.thumbnail { height: 200px; width:300px; overflow:hidden; position: relative; }
.thumbnail:hover .artistname { bottom: 0; }
.artistname { padding: 10px; width:100%; background-color: #000000; color: #ffffff; opacity: .5; position:absolute; bottom :-100px;  -webkit-transition:all .2s ease-in-out; -moz-transition:all .2s ease-in-out; -o-transition:all .2s ease-in-out; -ms-transition:all .2s ease-in-out; }

我正在使用 css 转换使转换看起来很漂亮,这不适用于 ie 9 和更低版本,但它会优雅地降级。

关于jquery - 将鼠标悬停事件添加到砌体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15571541/

相关文章:

javascript - 为什么我不能将 jquery 对象作为函数中的参数传递?

javascript - Uncaught ReferenceError : "$ is not defined"

html - CSS 不与导航栏 html 类对话

html - Img 未在 Safari 中显示,但在 Chrome 中显示

hover - Prolog 鼠标悬停识别器

javascript - clearInterval ,在鼠标悬停时停止计时器

javascript - 使用 JavaScript/jQuery 在任何给定元素上显示多个 CSS 值

javascript - 堆叠通知栏

css - IE8 中的 3d 按钮

javascript - 在循环内应用鼠标悬停事件监听器