0
I’m working on an article slider, whose articles are in a database that can be eleminated/added (CMS), everything is working perfectly, the database, and the slider. Now I just wanted to integrate the articles into the slider. Here’s my code, what’s happening is that the articles are all coming out at once on top of each other, some hint?
JS:
sliderInt=1;
sliderNext=2;
$("#newsText > p#1").fadeIn(500);
startSlider();
function startSlider() {
count = $("#newsText > p").size();
loop = setInterval (function() {
if (sliderNext>count) {
sliderNext = 1;
sliderInt = 1;
}
$("#newsText > p").fadeOut(500);
$("#newsText > p#" + sliderNext).delay(500).fadeIn(500);
sliderInt = sliderNext;
sliderNext ++;
} ,7500);
}
function stopLoop() {
window.clearInterval(loop);
}
function showSlide(id) {
stopLoop();
if (id>count) {
id = 1;
}
else if (id<1) {
id=count;
}
$("#newsText > p").fadeOut(500);
$("#newsText > p#" + id).fadeIn(500);
sliderInt = id;
sliderNext = id + 1;
startSlider();
}
})
PHP:
<?php
include_once('php/CMS/includes/connection.php');
include_once('php/CMS/includes/article.php');
?>
.......HTML....
<?php
for ($id=1; $id < count($articles); $id++) {
echo ("<p id=".$id.">".$articles[$id]['article_content']."</p>");
}
?>
I’ve updated the question above... what’s happening is that the articles are all appearing at the same time on top of each other
– Miguel
It seems to me that Javascript is having the slideshow start before the slides have been loaded. Have you tried placing Javascript at the bottom of the page or calling the function
startSlider();
within a$(document).load(callback)
?– Rodrigo Rigotti
Javascript is at the end, and if there are static p tags with ids numbered from 1 works very well, I think the error is in php. Obgado
– Miguel
Now that I’ve noticed, why are you assigning the same
id
on all Divs? By definition, you cannot haveid
s with the same name on a page. Take thatforeach
that is outside thefor
and use only thefor
in the names ofid
s.– Rodrigo Rigotti