Razvan <mi*****@mailci ty.com> wrote in message news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Hello,
Can somebody recommend me a Java Script scroller that can scroll an
i-frame ?
This is an update of a scroller I wrote long ago.
It will scroll any document, whether or not it's in an iframe.
I can't upload it to webspace currently, so here's the entire thing.
/**** SmartScroll (C)2000-05 Stephen Chalmers *************** ***
Provides CONTROLLABLE vertical auto scrolling of a document.
Best used to scroll frame windows containing long text passages.
Retains functionality of the vertical scroll bar, which additionally
is used to change scroll direction. Any horizontal offset is preserved.
Compatibility: NN4+ / Mozilla derivatives / IE4+ / Opera 5+
-- Installation --
Assuming the script is saved as smartscroll.js
<script type='text/javascript' src='smartscrol l.js'></script>
In the BODY tag, include: onload='SCstart Scroll()'
Optionally, set one or more user parameters thus:
<script type='text/javascript'>
SCdelay=130;
SCwrap=true;
SCmouseOver=fal se;
supportNN=true;
</script>
Their purpose is described below.
-- Setup --
To set the scroll speed, alter the value of 'SCdelay'. The higher the
value, the slower the scrolling. Default == 100.
There are two scroll modes, selected by setting the true/false state of 'SCwrap':
Alternate [false] - scroll direction changes at each end. (Default)
Wrap [true] - content scrolls upwards only, at bottom jumps back to top.
When using Wrap mode, to allow the text to disappear off the screen and re-appear
cleanly at the bottom, the page content should be padded with sufficient blank space,
top and bottom.
NOTE: Under Netscape 4.xx, if the page displays both scrollbars, scrolling may be erratic.
If this is likely to occur, set 'supportNN' to false.
-- Operation --
There are two control modes, selected by the true/false state of 'SCmouseover':
Mouseover [true] - Scrolling stops when the mouse is over the document and resumes
when it leaves.
Click [false] - Toggle scrolling ON/OFF by clicking anywhere on the page (or scrollbar
on Gecko browsers).
Toggle scroll direction with paired clicks anywhere on the page.
In both modes, change scroll direction by moving the scrollbar in the desired direction,
or with the up/down cursor keys (frame must have focus).
*** Do not edit below this line (unless you can't resist it) ***/
var SCpageY=0, SCxPoint=0, SCyPoint=0, SCup=-1, SCdn=1, SCdir=SCdn, SCmoved,
SCoffsetType=0, SColdY=-1, SCtravel=0, SCcount=-1, SCScrollEnable= true,
SCwait=1, SCpausedAt=0,
SCmouseOver=tru e,// - User variables -
SCdelay=100, // Alter these from script tags
SCwrap=false, // within the calling document.
supportNN=true; //
function SCgetPageX( idx )
{
var r=0;
switch(idx)
{
case 1 : r=window.pageXO ffset;break
case 2 : r=document.docu mentElement.scr ollLeft;break;
case 3 : r=document.body .scrollLeft;
}
return r;
}
function SCgetPageY( idx )
{
var r=0;
switch(idx)
{
case 1 : r=window.pageYO ffset;break
case 2 : r=document.docu mentElement.scr ollTop;break;
case 3 : r=document.body .scrollTop;
}
return r;
}
function SCSmartScroll()
{
SCnow=new Date();
if(SCScrollEnab le)
{
if(SCpausedAt) // paired-click detector
{
if(SCpausedAt+5 00 > SCnow.getTime() ) // compare current time with pause time
SCdir=-SCdir;
SCpausedAt=0;
}
SCxPoint=SCgetP ageX(SCoffsetTy pe);
// Read reported page position
SCyPoint=SCgetP ageY(SCoffsetTy pe);
if( (SCmoved=Math.a bs(SCtravel=(SC yPoint-SColdY))) >2 ) // Check for deviant movement
{ // caused by scrollbar use.
SCcount=-1;
if( (SCtravel<0 && SCdir==SCdn) || (SCtravel>0 && SCdir==SCup) )
SCdir=-SCdir;
SCpageY=SCyPoin t; // Update stored page position
}
else
if(SCmoved>0) // Check for movement..
SCcount=-1;
else
if(SCcount==-1) // on failure start counter
SCcount=SCwait;
if(SCcount==-1)
SColdY=SCyPoint ;
else // Wait period necessitated by NN, which intermittently
{ // delays reporting of correct Y position.
if(SCcount==0) // No movement after wait period,
if(SCwrap==true && SCdir>0) // wrap
SCpageY=0;
else
SCpageY=SColdY; // assume end reached and change direction
SCdir=-SCdir;
}
SCcount--;
}
window.scrollTo (SCxPoint, SCpageY+=SCdir) ; // move page
}
else
if(SCpausedAt== 0) // record time at pause
SCpausedAt=SCno w.getTime();
setTimeout("SCS martScroll()",S Cdelay);
}
function SCstartScroll()
{
SCoffsetType=(w indow.pageXOffs et!=null) ? 1
: ( document.compat Mode && document.compat Mode != 'BackCompat' ) ? 2
: ( document.body && typeof(document .body.scrollTop )!='undefined') ? 3
: 0;
if( document.layers )
if( supportNN==fals e )// Inhibit NN4 where selected.
SCoffsetType=0;
else
SCmouseOver=fal se;
if( SCoffsetType!=0 && window.scrollTo )
{
if(SCmouseOver)
if(window.Event && document.captur eEvents)
{
document.captur eEvents(Event.M OUSEOVER);
document.captur eEvents(Event.M OUSEOUT);
}
document.onmous eout=function() {SCScrollEnable =true;};
document.onmous eover=function( ){SCScrollEnabl e=false;};
}
else
{
if(window.Event && document.captur eEvents)
document.captur eEvents(Event.M OUSEUP);
document.onmous eup=function(){ SCScrollEnable^ =true;}
}
SCSmartScroll() ;
}
}