Javascript Rotator
#1
Posted 03 March 2010 - 09:20 PM
i just want to use text for this so i can style it with the css.
any thoughts?
TIA
#2
Posted 03 March 2010 - 09:45 PM
Quote
Do you mean like how to do it? Sure. You use javascript to change the message. CSS is always applied to an element, so no matter the message, the CSS will be applied to it. I answered a thread on here at some point about changing text using Javascript. I can't remember where it was though.
#3
Posted 03 March 2010 - 10:41 PM
#4
Posted 04 March 2010 - 12:48 AM
You could try giving this a go: http://simplythebest.net/scripts/DHTML_scr...script_131.html
This post has been edited by KamakaZ: 04 March 2010 - 12:48 AM
There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.
#5
Posted 04 March 2010 - 01:04 AM
EDIT: I tried that code and attempted changing the pics for text with no luck
This post has been edited by Chip Smith: 04 March 2010 - 01:05 AM
#6
Posted 04 March 2010 - 01:41 PM
#8
Posted 05 March 2010 - 04:49 PM
I'm not extremely familiar with javascript coding, and I can make some sense of the given code. However, to clarify, how would I use plain text with links or images in that rotating script?
My best guess:
<script type="text/javascript">
var i=0,
links = [
'Some text goes here',
'Some text with [link]web address[/link] goes here',
'[img]image[/img] Some text with image goes here'
],
seconds = 10;
function rotator(){
setTimeout("changeLink()", 1000 * seconds);
}
function changeLink(){
document.getElementById('myDiv').innerHTML = '<a href='+links[i]+'>' + links[i] + '</a>';
i+=1;
if(i===links.length){
i=0;
}
rotator(); }
</script>I'm sure my example is way off from what the actual markup is supposed to be in java language...but also, i wouldn't want each entry to be a link, only parts of the entry to be links, if necessary...I'm sure this is real confusing.
On a side note, I assume that I can style the 'myDiv' div in CSS to conform to the rest of the site?
#9
Posted 05 March 2010 - 05:24 PM
Quote
Yes.
Quote
You are working with HTML and Javascript. Java is something completely different.
The stuff that is contained in the array can simply be HTML (enclosed in single quotes). For instance, the contents of your array could look like this:
links = [ 'I am a Bing Link: <a href="http://www.bing.com">Click Here for Bing</a>', 'Click here for really cool things: <a href="www.bleepingcomputer.com">Malware Removal</a>', ..... ],
Then all you would need to do is change your javascript just slightly:
document.getElementById('myDiv').innerHTML = links[i];If you want a link first, or an image, or whatever you want, just add the HTML representation to the array.
#10
Posted 05 March 2010 - 05:26 PM
thanks again.
#11
Posted 05 March 2010 - 09:20 PM
I'm assuming that i need to change the div that's mentioned in the script (myDiv), change 'links', and 'rotator' all to be different names and then add it to the body onload....correct?
#12
Posted 05 March 2010 - 10:04 PM
#13
Posted 07 March 2010 - 02:17 AM
On another thought...when this is setup, there's a 10 sec delay when nothing is displayed. can the script be changed to display the first item as soon as the page is loaded?
#14
Posted 07 March 2010 - 08:51 AM
If you want a link there to begin with, then put it in the div like you normally would.

Help


Back to top









