开发者

How to fade in image in jQuery

I'm looking to on page load select a random image from either 1) a set 开发者_运维技巧like xml file or directory and randomly choose one and fade it in at medium speed.

Anyone?


$.getJSON("pictures.json", function(json){
    var pics = json.pictures;
    var pic = Math.floor(Math.random()*pics.length);
    $("img", { src: pics[pic] }).load(function(){
        $(this).fadeIn("slow");
    }).appendTo("body");
});

pictures.json

{ pictures: [ "apple.jpg", "pear.jpg", "orange.jpg", "bannana.jpg", "grapefruit.jpg" ] }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜