Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery:设置背景图像动画_Javascript_Jquery_Css - Fatal编程技术网

Javascript jQuery:设置背景图像动画

Javascript jQuery:设置背景图像动画,javascript,jquery,css,Javascript,Jquery,Css,通过修改脚本,我可以浏览背景图像,并通过body“background image”属性循环它们。然而,我想知道是否可以使用jqueryanimate(或其他方法)执行淡入淡出过渡。我曾尝试使用其他脚本,例如jQuery循环插件,但问题似乎是固定属性。以下是我迄今为止所做的工作: <style> body{ /*Remove below line to make bgimage NOT fixed*/ background-image:url(/sites/default/files

通过修改脚本,我可以浏览背景图像,并通过body“background image”属性循环它们。然而,我想知道是否可以使用jqueryanimate(或其他方法)执行淡入淡出过渡。我曾尝试使用其他脚本,例如jQuery循环插件,但问题似乎是固定属性。以下是我迄今为止所做的工作:

<style>
body{
/*Remove below line to make bgimage NOT fixed*/
background-image:url(/sites/default/files/bg-3.jpg);
background-attachment:fixed;
background-repeat: no-repeat;
background-size:100%;
}
</style>

<script type="text/javascript">
(function($){
$(document).ready(function(){
var bgimages=new Array()
bgimages[0]="/sites/default/files/bg-1.jpg"
bgimages[1]="/sites/default/files/bg-2.jpg"
bgimages[2]="/sites/default/files/bg-3.jpg"

//preload images
var pathToImg=new Array()
for (i=0;i<bgimages.length;i++){
pathToImg[i]=new Image()
pathToImg[i].src=bgimages[i]
}

var inc=-1

function bgSlide(){
if (inc<bgimages.length-1)
inc++
else
inc=0
$('body').css({'background-image':'url('+pathToImg[inc].src+')'});
}

setInterval(function(){
    bgSlide();
},3000);

});
})(jQuery)
</script>

身体{
/*删除下面的行以使bgimage不固定*/
背景图像:url(/sites/default/files/bg-3.jpg);
背景附件:固定;
背景重复:无重复;
背景大小:100%;
}
(函数($){
$(文档).ready(函数(){
var bgimages=新数组()
bgimages[0]=“/sites/default/files/bg-1.jpg”
bgimages[1]=“/sites/default/files/bg-2.jpg”
bgimages[2]=“/sites/default/files/bg-3.jpg”
//预加载图像
var pathToImg=新数组()

对于(i=0;i我相当肯定你不能完全做到这一点

您可以通过在内容后面放置一个div(或图像)作为背景来模拟这一点,类似于:


我很肯定你不能完全做到这一点

您可以通过在内容后面放置一个div(或图像)作为背景来模拟这一点,类似于:


David Walsh解释了如何使用MooTools来实现这一点。你可以看看!你也可以使用jQuery,MooTools只是一个不同的库


这里是演示:

David Walsh解释了如何使用MooTools来实现这一点。你可以看看!你也可以使用jQuery,MooTools只是一个不同的库

以下是演示:

您所说的“固定”属性是什么意思?您所说的“固定”属性是什么意思?