我该怎么做呢?我有以下代码可以更改背景图像:
var alt = false;
var delay = 5000;
var speed = ((delay / 3)*2);
var opacity = 1;
$( "#slider" ).slider({
orientation: "vertical",
range: "true",
min: 500,
max: 10000,
value: delay,
change: function( event, ui ) {
delay = ui.value;
}
});
setInterval(function() {
var r=Math.floor(Math.random()*b.length);
console.log(delay);
switch(alt)
{ case true:
$('#bg1').css("background-image", "url('"+b[r]+"')");
$('#bg1').fadeTo(speed,opacity);
$('#bg2').fadeOut(speed);
break;
case false:
$('#bg2').css("background-image", "url('"+b[r]+"')");
$('#bg2').fadeTo(speed,opacity);
$('#bg1').fadeOut(speed);
break;
}
alt = !alt;
}, delay);
更改滑块应该会更改变量,但不会。我不知道如何更改名为delay
.
编辑 现在我正在尝试这个,但它也不起作用,当我移动滑块时它会改变一次:
var alt = false;
var delay = 1000;
var speed = ((delay / 3)*2);
var opacity = 1;
var h;
function iSwap() {
var r=Math.floor(Math.random()*b.length);
console.log(delay);
switch(alt)
{ case true:
$('#bg1').css("background-image", "url('"+b[r]+"')");
$('#bg1').fadeTo(speed,opacity);
$('#bg2').fadeOut(speed);
break;
case false:
$('#bg2').css("background-image", "url('"+b[r]+"')");
$('#bg2').fadeTo(speed,opacity);
$('#bg1').fadeOut(speed);
break;
}
alt = !alt;
}
h = setInterval(iSwap(), delay);
$( "#slider" ).slider({
orientation: "vertical",
range: "true",
min: 500,
max: 10000,
value: delay,
change: function( event, ui ) {
delay = ui.value;
clearInterval(h);
h = setInterval(iSwap(), delay);
}
});