1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| var images = [ "test1.jpg", "test2.jpg", "test3.jpg", "test4.jpg" ];
$(images).each(function () { $('<img/>')[0].src = this; });
var index = 0;
$.backstretch(images[index], { speed: 500 },test);
function test() { $("#p_result").html("我是回调函数输出的结果 :"+index+""); } $("#btnChange").click(function () { index = Math.floor((Math.random()*images.length)); $.backstretch(images[index], { speed: 500 },test); }); $("#btnChange2").click(function () { setInterval(function () { index = (index >= images.length - 1) ? 0 : index + 1; $.backstretch(images[index], { speed: 500 },test); }, 3000); });
|