I am trying to modify the script below to slideshow/rotate through a handful of text DIVs.
I need these DIVs to appear in order-- div 1, then div 2, then div 3. Each would appear for 5 seconds, then show the next div... but in order.
The script below works well for Random divs, but I need them to be in order-- div 1, div 2, div 3... each time. - <div id="d1" style="display:none;">some text 1</div>
-
<div id="d2" style="display:none;">some text 2</div>
-
<div id="d3" style="display:none;">some text 3</div>
-
-
<script type="text/javascript">
-
divs = ['d1','d2','d3'];
-
-
function hideDivs() {
-
for (var i=0; i<divs.length; i++)
-
document.getElementById(divs[i]).style.display = 'none';
-
}
-
-
function showDiv() {
-
hideDivs(); //hide them all before we show the next one.
-
var randomDiv = divs[Math.floor(Math.random()*divs.length)];
-
var div = document.getElementById(randomDiv).style.display =
-
'block';
-
-
setTimeout(showDiv,500); //set a delay before showing the next div
-
}
-
-
showDiv();
-
</script>
10 2130
Please use code tags when posting code.
All you need to do is get rid of the random part and use a variable to track which sequential div to use next.
Thanks. How would I go about doing that? Nothing I've tried has worked, and I can't find anything that's a 'how to' about this online.
Please post one of the things you've tried so I can see where you went wrong.
Here's the most recent thing I tried. -
<script type="text/javascript">
-
divs = ['d1','d2','d3'];
-
-
function hideDivs() {
-
for (var i=0; i<divs.length; i++)
-
document.getElementById(divs[i]).style.display = 'none';
-
}
-
-
-
function showDiv() {
-
hideDivs(); //hide them all before we show the next one.
-
var Div1 = document.getElementById(d1).style.display =
-
'block';
-
var Div2 = document.getElementById(d2).style.display =
-
'block';
-
var Div3 = document.getElementById(d3).style.display =
-
'block';
-
-
setTimeout(showDiv,5000); //set a delay before showing the next div
-
}
-
-
showDiv();
-
For one thing, you hide them all, and then right away you display them all. You also need a variable to keep track of where you are in the sequence so you know which one to display.
I'm beyond lost.
Did I at least display a specific div right in this code?
If you're this lost, it would benefit you to work through a javascript tutorial before trying to write javascript. I recommend the one on w3schools.
You didn't display one correctly. You need to put the name of the div in quotes.
I'm just trying to edit an existing open source script, not write one. I've read tutorials and books, but I don't understand how to edit this script to do what we need it to.
I'll try adding quotes to this - var Div3 = document.getElementById('d3').style.display =
-
'block';
Please use code tags when posting code.
All that will do is make d3 visible. You still need to create a variable to track the next div you need to make visible.
You should be aware that editing a javascript necessitates that you write javascript. Therefore, learning and knowing the basics of javascript will greatly help your attempts in editing javascript.
Ah. I guess I should change my question to be:
"are there any open source scripts already out there that do what I am looking for here?"
Sign in to post your reply or Sign up for a free account.
Similar topics
by: yawnmoth |
last post by:
i'm trying to display text while a page is loading using a method
similar to the following:
<?
ob_end_flush();
echo 'AAA<br>';
flush();
sleep(10);
echo 'BBB';
?>
|
by: juglesh |
last post by:
Hello,
I need to look through the text on a page and replace certain words with an
image or other word
something like:
read document
find all instances of the word "blah"
change all...
|
by: Rex B |
last post by:
I need to rotate a text box, can't figure out how.
Can anyone point me in the right direction?
--
- -
Rex Burkheimer
WM Automotive
Fort Worth TX
|
by: Guoqi zheng |
last post by:
Dear sir,
I am using the default paging function of datagrid. Below is my code.
<PagerStyle NextPageText=">>>" PrevPageText="<<<"
HorizontalAlign="Center" Mode="NumericPages"></PagerStyle>
...
|
by: RC |
last post by:
First, this is a SVG issue, not 100% of XML issue. But I can't find
SVG group to post this. Since SVG is XML file, I post here hopefully
someone know both SVG and XML can help.
Here is my SVG...
|
by: Michael |
last post by:
Hi,
I have some wierdness that I can't figure out. Take a look at
www.members.iinet.net.au/~melacey
This is a very much cut down page to where I saw the problem, but it seems
to illustrate it,...
|
by: =?Utf-8?B?cHJhYmh1XzI3Xzg0?= |
last post by:
hi
i am creating many radio RadioButtonList dynamically in page load.its
working find.now i want to select a text in radio button(Autopostback is true
for radio buttonlist) and find that text in...
|
by: mccanaveras |
last post by:
Hello,
I don't know how I can rotate a text 45 or 90º. I'm looking forward to have an answer because I'm in a hurry.
Thanking you in anticipation for your cooperation
|
by: handique |
last post by:
Hi,
I have javascript code for rotating images, but the rotation starts only when mouse is placed over the image. But i want to rotate images automatically when the page loads. Can any guide me in...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |