首页 > 代码库 > 遍历输出图片加hover

遍历输出图片加hover

1.

$(".icon a>div").hover(function () {
            var slls = $(this).attr("class");
            slls = slls.replace("hi", "");
            $(this).css({ "background": "url(<%=site.path.themepath %>images/hicon" + slls + "h.jpg) no-repeat center #fff" });

         }, function () {
             var slls = $(this).attr("class");
             slls = slls.replace("hi", "");
             $(this).css({ "background": "url(<%=site.path.themepath %>images/hicon" + slls + ".jpg) no-repeat center #fff" });
        });

2.

for (var i = 1; i < 6; i++) {
            $(".icon a:eq(" + (i - 1) + ")>div").css({ "background": "url(<%=site.path.themepath %>images/hicon" + i + ".jpg) no-repeat center #fff" });
        }
        var iconhover = new Array(1, 2, 3, 4, 5);
        for (var j = 0; j < 5; j++) {
            $(".icon a:eq(" +j+ ")>div").hover(function () {
                var slls = $(this).attr("class");
                slls = slls.replace("hi", "");
                $(this).css({ "background": "url(<%=site.path.themepath %>images/hicon" + slls + "h.jpg) no-repeat center #fff" });

            }, function () {
                var slls = $(this).attr("class");
                slls = slls.replace("hi", "");
                $(this).css({ "background": "url(<%=site.path.themepath %>images/hicon" + slls + ".jpg) no-repeat center #fff" });
            });
        
        
        }
    });
  

 技术分享

 

遍历输出图片加hover