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" ] }
精彩评论