Forum Moderators: open
<script type="text/javascript">
$(function() {
var images = $('.home_page_pic img').hide();
var index = 0;
images.eq(index).show();
function swapImages()
{
images.eq(index).fadeOut(2000, function() {
index++;
if (index == images.length)
{
index = 0;
}
images.eq(index).fadeIn(2000, swapImages);
});
}
swapImages();
}); </script> <div class="home_page_pic">
<img src="images/animal_full_2.jpg" alt="">
<img src="images/church_full_1.jpg" alt="">
<img src="images/city_full_2.jpg" alt="">
<img src="images/faith_full_1.jpg" alt="">
<img src="images/flower_full_2.jpg" alt="">
<img src="images/gloom_full_2.jpg" alt="">
</div><!--END OF home_page_pic --> If an element has a display value of inline, then is hidden and shown, it will once again be displayed inline..
<div class="home_page_pic">
<img src="images/animal_full_2.jpg" alt="" style="display:block">
<img src="images/church_full_1.jpg" alt="" style="display:block">
<img src="images/city_full_2.jpg" alt="" style="display:block">
<img src="images/faith_full_1.jpg" alt="" style="display:block">
<img src="images/flower_full_2.jpg" alt="" style="display:block">
<img src="images/gloom_full_2.jpg" alt="" style="display:block">
</div><!--END OF home_page_pic --> display:block; in the css too?
$(function() {
swapImages();
});
$(function() {
var images = $('.home_page_pic img').hide();
var index = 0;
images.eq(index).show();
swapImages();
function swapImages()
{
images.eq(index).fadeOut(2000, function() {
index++;
if (index == images.length)
{
index = 0;
}
images.eq(index).fadeIn(2000, swapImages);
});
}
swapImages();
});
var images = $('.home_page_pic img').hide();
var index = 0;
images.eq(index).show();
swapImage();?
$(window).load(
function() {
swapImages();
});
});
$(window).load(
function() {
var images = $('.home_page_pic img').hide();
var index = 0;
images.eq(index).show();
function swapImages()
{
images.eq(index).fadeOut(2000, function() {
index++;
if (index == images.length)
{
index = 0;
}
images.eq(index).fadeIn(2000, swapImages);
});
}
});
swapImages();
});
So I made each image block, do I have to add display:block; in the css too?
I am not quite sure what you mean about the function
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled</title>
<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<style type="text/css">
/* other than the positioning properties,
the other values are for my test, set accordingly
*/
#home_page_pic,#home_page_pic img {
width:975px;
height: 375px;
}
#home_page_pic {
position: relative;
margin: 0 auto;
border: 1px solid #000;
}
#home_page_pic img {
/* Will default to top:0; left:0; which is what we want */
position: absolute;
display:none;
}
</style>
<script type="text/javascript">
$(window).load(
function() {
swapImages();
});
//
$(function() {
images = $('#home_page_pic img').hide();
index = 0;
images.eq(index).show();
});
//
function swapImages() {
images.eq(index).fadeOut(2000, function() {
index++;
if (index == images.length) { index = 0; }
images.eq(index).fadeIn(2000, swapImages);
});
}
</script>
</head>
<body>
<div id="home_page_pic">
<!-- use ID if only one on the page, class not necessary -->
<img src="images/image-1.jpg" alt="">
<img src="images/image-2.jpg" alt="">
<img src="images/image-3.jpg" alt="">
<img src="images/image-4.jpg" alt="">
<img src="images/image-5.jpg" alt="">
<img src="images/image-6.jpg" alt="">
</div><!--END OF home_page_pic -->
</body>
</html>
$(window).load(
function() {
var images = $('.home_page_pic img').hide();
var index = 0;
images.eq(index).show();
function swapImages()
{
images.eq(index).fadeOut(2000, function() {
index++;
{
index = 0;
}
images.eq(index).fadeIn(2000, swapImages);
});
}
swapImages();
});
$(window).load(
function() {
swapImages();
});
$(function() {
images = $('#home_page_pic img').hide();
index = 0;
images.eq(index).show();
});
function swapImages() {
images.eq(index).fadeOut(2000, function() {
index++;
if (index == images.length) { index = 0; }
images.eq(index).fadeIn(2000, swapImages);
});
}
$(function() {
images = $('#home_page_pic img').hide();
index = 0;
images.eq(index).show();
});
$(function() {
var images = $('.home_page_pic img').hide();
var index = 0;
images.eq(index).show('fast');
function swapImages()
{
images.eq(index).fadeOut(2000, function() {
index++;
if (index == images.length)
{
index = 0;
}
images.eq(index).fadeIn(2000, swapImages);
});
}
swapImages();
});
images.eq(index).show(); to images.eq(index).show('fast'); and now everything works. I don't know why that made a difference, maybe you can explain it to me : -) I don't have a clue. If you look at the live site (again apologies for adding the url so many times) [antobbo.webspace.virginmedia.com...] you will see that the glitch has disappeared. <img src="images/animal_full_2.jpg" alt="" style="display: inline; ">
<img src="images/church_full_1.jpg" alt="" style="display: block; opacity: 0.8300663891173443; ">
...
<img src="images/animal_full_2.jpg" alt="" style="display: none; ">
<img src="images/church_full_1.jpg" alt="" style="display: block; opacity: 0.3567377236361008; "> and I don't quite understand when this bit... gets executed because the script calls the swapImage()... );
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled</title>
<!-- tested with local images, set values accordingly -->
<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<style type="text/css">
/* other than the positioning properties,
the rest is for my test
*/
#home_page_pic,#home_page_pic img {
width:975px;
height: 375px;
}
#home_page_pic {
position: relative;
margin: 0 auto;
border: 1px solid #000;
}
#home_page_pic img {
position: absolute;
display:none;
}
</style>
<script type="text/javascript">
$(window).load(
function() {
images = $('#home_page_pic img');
index = 0;
swapImages();
});
//
function swapImages() {
images.eq(index).fadeOut(2000, function() {
index++;
if (index == images.length) { index = 0; }
images.eq(index).fadeIn(2000, swapImages);
});
}
</script>
</head>
<body>
<div id="home_page_pic">
<!-- use ID if only one on the page, class not necessary -->
<img src="images/image-1.jpg" alt="">
<img src="images/image-2.jpg" alt="">
<img src="images/image-3.jpg" alt="">
<img src="images/image-4.jpg" alt="">
<img src="images/image-5.jpg" alt="">
<img src="images/image-6.jpg" alt="">
</div><!--END OF home_page_pic -->
</body>
</html>