In this javascript tutorial we will learn how to develop text slideshow in javascript. Sometimes it become a necessary requirement to develop a text slideshow in the website so to avoid use of Flash because flash makes the webpage heavier and sometimes reader of the website don’t have any flash reader installed in web browser so its better to use javascript to develop the text slideshow.
<head>
<title>Text Slideshow in javascript</title>
<script type="text/javascript" language="javascript">
var slideArray = new Array()
slideArray[0]= "Here comes the <strong>First Slide</strong>.<br> Some of text goes here ";
slideArray[1]= "<strong>Second Slide</strong>.<br> Some of text goes here ";
{
document.getElementById('div_display').innerHTML=slideArray[0];
setTimeout("secondSlide()",10000);
}
function secondSlide()
{
document.getElementById('div_display').innerHTML=slideArray[1];
setTimeout("firstSlide()",10000);
}
</script>
</head>
<table width="100%" cellpadding="2" cellspacing="2">
<tr>
<td>
<div id="div_display"><script type="text/javascript" language="javascript">firstSlide();</script></div>
</td>
</tr>
</table>
</body>
</html>
Now it’s turn to understand the code.
var slideArray = new Array()
slideArray[0]= "Here comes the <strong>First Slide</strong>.<br> Some of text goes here ";
slideArray[1]= "<strong>Second Slide</strong>.<br> Some of text goes here";
slideArray[3]= "<strong>Fourth Slide</strong>.<br> Some of text goes here";
{
var total_slides;
total_slides=Math.floor(Math.random()*slideArray.length)
document.getElementById('div_display').innerHTML=slideArray[total_slides];
setTimeout("textSlideShow()",10000);
}
</script>
<div id="div_display"><script type="text/javascript" language="javascript"> textSlideShow();</script></div>
Every time you will get random slide.
First of all use any web programming language such as php, asp.net, asp to get data from database and then assign that data to different textboxes and hide these textboxes then do this to get data from textbox and use that data as a text in slideshow.
<head>
<title>Text Slideshow in javascript</title>
<script type="text/javascript" language="javascript">
var slideArray = new Array()
var myName,myAge;
function firstSlide()
{
myName=document.getElementById('txt_Name').value;
slideArray[0]=myName;
document.getElementById('div_display').innerHTML=slideArray[0];
setTimeout("secondSlide()",10000);
}
function secondSlide()
{
myAge =document.getElementById('txt_Age').value;
slideArray[1]=myAge;
document.getElementById('div_display').innerHTML=slideArray[1];
setTimeout("firstSlide()",10000);
}
</script>
</head>
<body>
<table width="100%" cellpadding="2" cellspacing="2">
<form name="form1">
<tr>
<td>
<input type="text" id="txt_Name" style="display:none;" value="Hello"><br>
<input type="text" id="txt_Age" style="display:none;" value="Hello2">
</td>
</tr>
</form>
</table>
</body>
</html>
Happy Coding…!
10 comments:
This is GREAT!! But if you want to change the font and size... How do you do it?
total_slides=Math.floor(Math.random()*slideArray.length)
Throws a syntax error
Hy erockodessey, please check your javascript code, because this code is working fine.
this is gr8
how do you change font color and add a link?
Just change the end of your function to include: .fontcolor("color");
Ex:
function firstSlide()
{
document.getElementById('div_display').innerHTML=slideArray[0].fontcolor("black");
setTimeout("secondSlide()",10000);
}
How would you center the text?
Thanks for the code.
You can center align text by using align attribute of div which is
<div id="div_display" align="center"><script type="text/javascript" language="javascript">firstSlide();</script></div>
OR
if you want to center align the text of any specific slide then you can write your code just like this
function firstSlide()
{
document.getElementById('div_display').innerHTML=slideArray[0].fontcolor("red");
document.getElementById('div_display').style.textAlign="center";
setTimeout("secondSlide()",10000);
}
how do I put links to it? thanks
Wow!!! Thank you!!! I was looking for a text slideshow and didn't think I would get one!!!!!
http:\\sincerelykeff.blogspot.com
Slideshow is at bottom.
Post a Comment