Javascript 带有四个淡入淡出图像的幻灯片无法更改div';s位置

Javascript 带有四个淡入淡出图像的幻灯片无法更改div';s位置,javascript,jquery,css,Javascript,Jquery,Css,我有一个名为“background”的div,其中有4个图像(400x300px),每x秒一行淡入淡出。此代码在浏览器的左上角显示图像。我想把它移到另一个地方,在一个容器里,但我不能。我尝试将位置更改为“相对”,并使用“边距”,div“背景移动到我设置的任何位置,但fadeIn Out图像仍保留在左上角。 下面你可以看到代码。有什么想法吗 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-eq

我有一个名为“background”的div,其中有4个图像(400x300px),每x秒一行淡入淡出。此代码在浏览器的左上角显示图像。我想把它移到另一个地方,在一个容器里,但我不能。我尝试将位置更改为“相对”,并使用“边距”,div“背景移动到我设置的任何位置,但fadeIn Out图像仍保留在左上角。 下面你可以看到代码。有什么想法吗

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Image Change</title>
<style type="text/css">
div.background {
position:relative;
width:500px;
height:500px;
margin-left:50px;
margin-top:50px;
background:red;
z-index:-1;}

div.background img {
position:fixed;
list-style: none;
left:0px;
top:0px;}

div.background ul li.show {
z-index:500}

div.background {    position:absolute;  left:0px;   top:0px;    z-index:-1;}div.background img {       position:fixed;  list-style: none;   left:0px;   top:0px;}div.background ul li.show {    z-index:500}
</style>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript">
function thebackground() {
$('div.background img').css({opacity: 0.0});
$('div.background img:first').css({opacity: 1.0});
setInterval('change()',4000);
}
function change() {
var current = ($('div.background img.show')? $('div.background img.show') : $('div.background img:first'));
if ( current.length == 0 ) current = $('div.background img:first');
var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.background img:first')    :current.next()) : $('div.background img:first'));
next.css({opacity: 0.0})
.addClass('show')
.animate({opacity: 1.0}, 1000);
current.animate({opacity: 0.0}, 1000)
.removeClass('show');
};
$(document).ready(function() {
thebackground();
$('div.background').fadeIn(1000); // works for all the browsers other than IE
$('div.background img').fadeIn(1000); // IE tweak
});
</script>


</head>

<body>
<div class="background">
<img src="images/image1.jpg"  />
<img src="images/image2.jpg"  />
<img src="images/image3.jpg"  />
<img src="images/image4.jpg"  />

</div>
</body>
</html>

图像变化
部门背景{
位置:相对位置;
宽度:500px;
高度:500px;
左边距:50像素;
边缘顶部:50px;
背景:红色;
z-索引:-1;}
部门背景图像{
位置:固定;
列表样式:无;
左:0px;
顶部:0px;}
节目背景{
z指数:500}
div.background{position:absolute;left:0px;top:0px;z-index:-1;}div.background img{position:fixed;列表样式:none;left:0px;top:0px;}div.background ul li.show{z-index:500}
函数thebackground(){
$('div.background img').css({opacity:0.0});
$('div.background img:first').css({opacity:1.0});
setInterval('change()',4000);
}
函数更改(){
当前变量=($('div.background img.show')?$('div.background img.show'):$('div.background img:first');
如果(current.length==0)current=$('div.background img:first');
var next=((current.next().length)?((current.next().hasClass('show'))?$('div.background img:first'):current.next():$('div.background img:first');
css({opacity:0.0})
.addClass('show')
.animate({opacity:1.0},1000);
动画({opacity:0.0},1000)
.removeClass(“show”);
};
$(文档).ready(函数(){
背景();
$('div.background').fadeIn(1000);//适用于除IE以外的所有浏览器
$('div.background img').fadeIn(1000);//IE调整
});

这是您预期的结果吗

在这种情况下,尝试将CSS更改为
位置:相对
位置:绝对

div.background {position:relative; left:0px; top:0px; z-index:-1;}
div.background img {position:absolute; left:0px; top:0px;}
还更改了这一行:

setInterval('change()',4000);

setInterval(change(),4000);