Razvan <mi*****@mailcity.com> wrote in message news:11**********************@g44g2000cwa.googlegr oups.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='smartscroll.js'></script>
In the BODY tag, include: onload='SCstartScroll()'
Optionally, set one or more user parameters thus:
<script type='text/javascript'>
SCdelay=130;
SCwrap=true;
SCmouseOver=false;
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=true,// - 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.pageXOffset;break
case 2 : r=document.documentElement.scrollLeft;break;
case 3 : r=document.body.scrollLeft;
}
return r;
}
function SCgetPageY( idx )
{
var r=0;
switch(idx)
{
case 1 : r=window.pageYOffset;break
case 2 : r=document.documentElement.scrollTop;break;
case 3 : r=document.body.scrollTop;
}
return r;
}
function SCSmartScroll()
{
SCnow=new Date();
if(SCScrollEnable)
{
if(SCpausedAt) // paired-click detector
{
if(SCpausedAt+500 > SCnow.getTime()) // compare current time with pause time
SCdir=-SCdir;
SCpausedAt=0;
}
SCxPoint=SCgetPageX(SCoffsetType);
// Read reported page position
SCyPoint=SCgetPageY(SCoffsetType);
if( (SCmoved=Math.abs(SCtravel=(SCyPoint-SColdY))) >2 ) // Check for deviant movement
{ // caused by scrollbar use.
SCcount=-1;
if( (SCtravel<0 && SCdir==SCdn) || (SCtravel>0 && SCdir==SCup) )
SCdir=-SCdir;
SCpageY=SCyPoint; // 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=SCnow.getTime();
setTimeout("SCSmartScroll()",SCdelay);
}
function SCstartScroll()
{
SCoffsetType=(window.pageXOffset!=null) ? 1
: ( document.compatMode && document.compatMode != 'BackCompat' ) ? 2
: ( document.body && typeof(document.body.scrollTop)!='undefined') ? 3
: 0;
if( document.layers )
if( supportNN==false )// Inhibit NN4 where selected.
SCoffsetType=0;
else
SCmouseOver=false;
if( SCoffsetType!=0 && window.scrollTo )
{
if(SCmouseOver)
if(window.Event && document.captureEvents)
{
document.captureEvents(Event.MOUSEOVER);
document.captureEvents(Event.MOUSEOUT);
}
document.onmouseout=function(){SCScrollEnable=true ;};
document.onmouseover=function(){SCScrollEnable=fal se;};
}
else
{
if(window.Event && document.captureEvents)
document.captureEvents(Event.MOUSEUP);
document.onmouseup=function(){SCScrollEnable^=true ;}
}
SCSmartScroll();
}
}