Forum Moderators: open
I'm wanting to put a scroller on my site, meaning like a divbox that contains some text and images that are scrolling and pausing
Example:
Text Text Text Text Text Text Text Text Text Text <img>
<link>
pause then scroll to
Text Text Text Text Text Text Text Text Text Text <img>
<link>
pause then scroll to
Text Text Text Text Text Text Text Text Text Text <img>
<link>
I got one from the net, but the problem is that it doesn't work very well when you resize the text. The scrollers I found were all depending on having normal size text..
Is there a way around this? Would appreciate any help! Thank you!
That being said -- something that doesn't work if the text size changes is not a very good solution, as you can never guarantee that the user will have the exact same settings as you.
Well, the problem is that if I change the css proportion settings to auto, height: auto; width: auto;, it works. The script that I was using uses more then one div though, and when it changes from one div to another it changes the size of the box (which has borders). Between the divs the box disappears (only the border remains)..
this is the script from the <head>tag:
<link rel="stylesheet" href="../layoutcss/scroll.css" type="text/css">
<script type="text/javascript">
var pausecontent=new Array()
pausecontent[0]='<h3>Fransisco</h3><img class="bild" src="../bilder/chico.jpg">text text text text<br><br><a href="berattelser/max.htm">Läs fortsättningen här</a>'
pausecontent[1]='<h3>Max</h3><img class="bild" src="../bilder/max.jpg">text text text text <br><br><a href="berattelser/max.htm">Läs mer här</a>'
pausecontent[2]='<h3>Ugglessons</h3><img class="bild" src="../bilder/chico.jpg">text text text text<br><br><a href="berattelser/max.htm">Läs fortsättningen här</a>'
</script>
<script type="text/javascript">
/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit [dynamicdrive.com...] for this script and 100s more.
***********************************************/
function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}
// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------
pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}
// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------
pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}
// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------
pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}
pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}
// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------
pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}
pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}
</script>
and this is what's in the body:
<script type="text/javascript">
//new pausescroller(name_of_message_array, CSS_ID, CSS_classname, pause_in_miliseconds)
new pausescroller(pausecontent, "pscroller1", "someclass", 5000)
</script>
With the css to go with it:
#pscroller1{
width: 200px;
height: 190px;
border: 0;
padding: 5px;
overflow:auto;
}
.someclass{
}
I borrowed the script from dynamic drive, since I can't code javascript myself. Apply it to a page and set the proportions to auto, it gets really interesting :)
Thanks for your help m8 :)
The problem with most tickers (as you have already noticed) is that they depend on plain text, which again depends on browser settings ... which then becomes resizable.
That's not to say that you cannot solve the problem in JS ... But I need to know if you the box is fixed in size, or if you would consider allowing it resize to fit the text.
Either way -- there is a solution. There are even ways to force the text to be a certain size. But, I'll get to that ...
The size of the box should resize when you resize the text. It gets really weird when it resizes everytime the text inside the box changes.. Other then that the size of the box isn't that important, I don't know in what sence you were speaking?
"______________
¦ ¦
¦ ¦
¦ ¦
¦ ¦
¦____________¦
A box like that, but alot bigger is the basic thought. In this box, text is scrolling vertically. It gives a pause on every paragraph since every paragraph will be talking about a different child (the site is for an orphanage)and showing a picture of this child. So:
picture¦ text about the child text about the child
picture¦ text about the child text about the child
picture¦ text about the child text about the child
picture¦ text about the child text about the child
picture¦ text about the child text about the child
text about the child text about the child
link to read the continuation to the text above
shows for a few seconds, then the text moves upwards and out of the box and in comes another text about another child. It gives a pause for the visitors to read this and then goes on to the next child. "
That's what I'm after, and it's not supposed to stop working correctly when you resize your text... :)