我有一个脚本,根据我滚动的位置切换背景图像。我能够正确切换背景图像,但是有人要求我使背景图像使用 fadeIn()
而不是简单更改。基本上,我正在循环遍历背景图像,我希望以前的背景图像 fadeOut()
,下一个背景图像 fadeIn()
。是否可能做到这一点?如果可以,怎么做?以下是这个脚本。
$("#scroll").on("slidestart", function(ev, ui){
$(this).on("mousemove touchmove", function(){
var slider_pos = $("span").offset().top;
$("#menu").find(".schematics").each(function(ev){
var schematic_id = $(this).data("id").split("_")[0];
var schematic_top = $(this).offset().top;
var schematic_height = $(this).height();
var schematic_bottom = (schematic_top + schematic_height);
var url = $(this).data("url");
这里是背景图片更改的地方。我认为在 CSS 操作之后添加 fadeIn()
应该可以工作,但事实并非如此。
if((slider_pos >= schematic_top) && (slider_pos <= schematic_bottom)){
$("#plane_image").css("background-image", "url(" +url +")").fadeIn("slow");
$(".vis").hide();
$(".title").hide();
$("#" +schematic_id +"_list").show();
$("#" +schematic_id +"_head").show();
}
})
})
})
fadeIn()
可以解决问题...但是图片加载时会有延迟吗?这样它会在fadeIn
完成后加载和显示吗? - Ted