Слайд с четырьмя изображениями fadeIn-Out не может изменить положение div

0

У меня есть div с именем "background", и внутри него есть 4 изображения (400x300px), которые затухают и выходят в строке каждые x секунд. Этот код отображает изображения в верхнем левом углу браузера. Я хочу переместить его в другое место, в контейнер, но я не могу. Я попытался изменить позицию на "relative" и "margin", фон 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>
Теги:

1 ответ

1
Лучший ответ

Это ваш ожидаемый результат?

http://jsfiddle.net/wH7zN/

В этом случае попробуйте изменить CSS на position: relative и position: absolute:

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);

Ещё вопросы

Сообщество Overcoder
Наверх
Меню