Hi All,
I am a COMPLETE newbie to javascript… actually i dont really know the first thing about it yet but i have a div on a site that uses javascript to fade in and out text.
All i want to do is but a line break / return in the text.
Im sure this has been asked before but i couldnt find anything accept for one guy suggesting using ‘/n’ but that didnt work.
Here’s the script:
arrFadeTitles[0] = "A line of text here. PAGE BREAK HERE. More text here";
Thanks in advance.
Any white-space character, including line break, renders as a regular space (U+0020) in HTML. Furthermore, multiple adjacent spaces collapse into one.
You can use a <br>
element as Paul says, or you can use CSS to specify that white-space be rendered literally (e.g., white-space:pre
).
Hi Everyone,
Yeah thats what i thought it was (i just wrote the backslash wrong in the post oops!) but its not working…
Any ideas why?
Heres the whole script:
function setupFadeLinks() {
//add as many as you want
//the links are the arrFadeLinks
arrFadeLinks[0] = "http://javascriptsource.com/snippets/popup-blocker-detection.html";
//the title are the arrFadeTitles
arrFadeTitles[0] = "A line of text here.\
This should be a new line";
arrFadeLinks[1] = "what.php";
arrFadeTitles[1] = "A line of text here.\
More text here";
arrFadeLinks[2] = "what.php";
arrFadeTitles[2] = "A line of text here.\
This should be a new line";
arrFadeLinks[3] = "what.php";
arrFadeTitles[3] = "A line of text here.\
More text here";
arrFadeLinks[4] = "what.php";
arrFadeTitles[4] = "5. insertAfter()";
arrFadeLinks[5] = "what.php";
arrFadeTitles[5] = "6. insertAfter()";
arrFadeLinks[6] = "what.php";
arrFadeTitles[6] = "7. insertAfter()";
}
// You can also play with these variables to control fade speed, fade color, and how fast the colors jump.
//fade out
var m_FadeOut = 200;
//try and leave this 1 under 50
var m_FadeIn=50;
//dont no yet lol
var m_Fade = 0;
//dont yet lol but it changes some thing lol
var m_FadeStep = 10;
//fade wait
var m_FadeWait = 1600;
var m_bFadeOut = true;
var m_iFadeInterval;
window.onload = Fadewl;
var arrFadeLinks;
var arrFadeTitles;
var arrFadeCursor = 0;
var arrFadeMax;
function Fadewl() {
m_iFadeInterval = setInterval(fade_ontimer, 10);
arrFadeLinks = new Array();
arrFadeTitles = new Array();
setupFadeLinks();
arrFadeMax = arrFadeLinks.length-1;
setFadeLink();
}
function setFadeLink() {
var ilink = document.getElementById("fade_link");
ilink.innerHTML = arrFadeTitles[arrFadeCursor];
ilink.href = arrFadeLinks[arrFadeCursor];
}
function fade_ontimer() {
if (m_bFadeOut) {
m_Fade+=m_FadeStep;
if (m_Fade>m_FadeOut) {
arrFadeCursor++;
if (arrFadeCursor>arrFadeMax)
arrFadeCursor=0;
setFadeLink();
m_bFadeOut = false;
}
} else {
m_Fade-=m_FadeStep;
if (m_Fade<m_FadeIn) {
clearInterval(m_iFadeInterval);
setTimeout(Faderesume, m_FadeWait);
m_bFadeOut=true;
}
}
var ilink = document.getElementById("fade_link");
if ((m_Fade<m_FadeOut)&&(m_Fade>m_FadeIn))
ilink.style.color = "#" + ToHex(m_Fade);
}
function Faderesume() {
m_iFadeInterval = setInterval(fade_ontimer, 10);
}
function ToHex(strValue) {
try {
var result= (parseInt(strValue).toString(16));
while (result.length !=2)
result= ("0" +result);
result = result + result + result;
return result.toUpperCase();
}
catch(e)
{
}
}
Cheers!
If you look at the source code you will find that
is working.
If you want the break to appear on the rendered HTML code, you will need to use <br> to affect the on-page display of the text.
O.o, **** that’s embarrassing
A line break in JavaScript is "\
" (note the backslash).
arrFadeTitles[0] = "A line of text here.\
More text here";
You are confusing JavaScript and PHP.
In JavaScript either "
" or ’
’ is a linefeed whereas in PHP you can only use "
".
Just to add onto [COLOR=#663300][B][I]AutisticCuckoo[/I][/B][/COLOR]'s post but you should also note
only works when the string is encased with double quotes "
"