AnitaB Posted April 16, 2009 Report Share Posted April 16, 2009 I am trying to create a rolling text box and am having some difficulty. The box shows up but the text is not rolling. Can anyone help? The code I used is as follows: The HTML code: Text for scrolling box here. initSlidingContent('scrollingContainer',3); The CSS code: #scrollingContainer{ width:120px; height:160px; background-color: #E2EBED; float:left; margin-right:10px; font-size:0.9em; } Thanks! Anita Quote Link to comment Share on other sites More sharing options...
Andrea Posted April 16, 2009 Report Share Posted April 16, 2009 Maybe it has to do with the JavaScript that's supposed to make it scroll? Quote Link to comment Share on other sites More sharing options...
AnitaB Posted April 16, 2009 Author Report Share Posted April 16, 2009 Sorry, here is that code which I placed in my index.html file after the above html code: (now that's everything I have for the rolling text box) var slideTimeBetweenSteps = 30; // General speed variable (Lower = slower) var scrollingContainer = false; var scrollingContent = false; var containerHeight; var contentHeight; var contentObjects = new Array(); var originalslideSpeed = false; function slideContent(containerId) { var topPos = contentObjects[containerId]['objRef'].style.top.replace(/[^\-0-9]/g,''); topPos = topPos - contentObjects[containerId]['slideSpeed']; if(topPos/1 + contentObjects[containerId]['contentHeight']/1<0)topPos = contentObjects[containerId]['containerHeight']; contentObjects[containerId]['objRef'].style.top = topPos + 'px'; setTimeout('slideContent("' + containerId + '")',slideTimeBetweenSteps); } function stopSliding() { var containerId = this.id; contentObjects[containerId]['slideSpeed'] = 0; } function restartSliding() { var containerId = this.id; contentObjects[containerId]['slideSpeed'] = contentObjects[containerId]['originalSpeed']; } function initSlidingContent(containerId,slideSpeed) { scrollingContainer = document.getElementById(containerId); scrollingContent = scrollingContainer.getElementsByTagName('DIV')[0]; scrollingContainer.style.position = 'relative'; scrollingContainer.style.overflow = 'auto'; scrollingContent.style.position = 'relative'; scrollingContainer.onmouseover = stopSliding; scrollingContainer.onmouseout = restartSliding; originalslideSpeed = slideSpeed; scrollingContent.style.top = '0px'; contentObjects[containerId] = new Array(); contentObjects[containerId]['objRef'] = scrollingContent; contentObjects[containerId]['contentHeight'] = scrollingContent.offsetHeight; contentObjects[containerId]['containerHeight'] = scrollingContainer.clientHeight; contentObjects[containerId]['slideSpeed'] = slideSpeed; contentObjects[containerId]['originalSpeed'] = slideSpeed; slideContent(containerId); } Quote Link to comment Share on other sites More sharing options...
newseed Posted April 16, 2009 Report Share Posted April 16, 2009 I think the script is fine. Just make sure its placed between the tags. Quote Link to comment Share on other sites More sharing options...
AnitaB Posted April 16, 2009 Author Report Share Posted April 16, 2009 (edited) Thanks!! It's working! However, the only line that is not validating is: if(topPos/1 + contentObjects[containerId]['contentHeight']/1<0)topPos = contentObjects[containerId]['containerHeight']; with the "<" highlighted and the following error message: This message may appear in several cases: You tried to include the "<" character in your page: you should escape it as "<" You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&", which is always safe. Another possibility is that you forgot to close quotes in a previous tag. Do you know why that might be the case? Thanks again! Anita Edited April 16, 2009 by AnitaB Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted April 16, 2009 Report Share Posted April 16, 2009 I think that in order to validate, the javascript needs to be placed in an external file and called from the file. or place CDATA tokens around the script. Can't remember exactly. Not a big js user here. Quote Link to comment Share on other sites More sharing options...
newseed Posted April 16, 2009 Report Share Posted April 16, 2009 jlhaslip is correct. It's better to put it in it's own file and then link it in your . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.