"scroll end" event?

S

Simon Wigzell

Can I trap when the scroll is ended? This is what I want - the calculator
disapears when the site visitor starts scrolling the main page. I'm doing
that with an "onScroll()" function. I'm bringing the calculator back with a
"onMouseup()" which I thoguht would activate when the scroll bar was
released but it doesn't. What I really want is an "offScroll()" but there is
no such thing!

http://www.mississippiprinting.com/...ES&PRODUCT=Full Color Brochure&PageSize=8 x 9
 
S

Stephen Chalmers

What I really want is an "offScroll()" but there is
no such thing!

Think carefully about what you are asking. The process of scrolling
consists of a series of sequential scroll actions, each of which moves the
page by a set amount, and each must end before another can start. What would
determine the triggering of an 'offscroll'event?
To re-show your div or whatever, you need to monitor the time that the page
displacement has remained the same.
In addition to using the onscroll event to hide the div, it could
set/refresh a timeout for restoring visibility.
 
S

Simon Wigzell

Surely it is possible to trap the "onmouseup" event when the user has
finished "dragging" and "lets go of" the scroll bar? "onmouseup" can be
trapped within the rest of the browser window?
 
S

Stephen Chalmers

Simon Wigzell said:
Surely it is possible to trap the "onmouseup" event when the user has
finished "dragging" and "lets go of" the scroll bar? "onmouseup" can be
trapped within the rest of the browser window?
Yes, but the scrollbar isn't classed as part of the window (except by
Mozilla).
You may be able to use <body onmouseover=... or the scripted equivalent, but
I would much prefer the way I suggested.
BTW, your current code is not cross-browser, and there is an error in the
CenterIt() function related to the scope of a variable.
 
R

rf

Simon Wigzell said:
Surely it is possible to trap the "onmouseup" event when the user has
finished "dragging" and "lets go of" the scroll bar? "onmouseup" can be
trapped within the rest of the browser window?

What if your viewer uses that arrow keys or page down/up keys to scroll?

What if your viewer uses the mouse wheel to scroll?

Cheers
Richard.
 
D

DU

Simon said:
Can I trap when the scroll is ended? This is what I want - the calculator
disapears when the site visitor starts scrolling the main page. I'm doing
that with an "onScroll()" function. I'm bringing the calculator back with a
"onMouseup()" which I thoguht would activate when the scroll bar was
released but it doesn't. What I really want is an "offScroll()" but there is
no such thing!

http://www.mississippiprinting.com/MPCNew/MPCProduct.asp?MainPageName=Brochures& PageName=8%20x%209&FIRSTTIME=YES&PRODUCT=Full%20Color%20Brochure&PageSize=8%20x%209

Your code is far from correct, interoperable and cross-browser. Even if
you choose to support only MSIE, your code as it is does not make a lot
of sense. You never define unit values in your css declarations and that
falls under error conditions in CSS. OTOH, you want to support MSIE when
in standards compliant rendering mode with
var root = (document.compatMode == "CSS1Compat"?
document.documentElement: document.body);
which is desirable but your code is incoherent with such praiseworthy goal.

IMO, you first need to validate your markup code and CSS code before
going any further.

DU
 
D

DU

rf said:
What if your viewer uses that arrow keys or page down/up keys to scroll?

What if your viewer uses the mouse wheel to scroll?

Cheers
Richard.

All of these don't matter if you properly set a scroll event listener on
the window.

http://www10.brinkster.com/doctorunclear/BrowserBugsSection/MozillaBugs/Bug189308_ScrollEvent.html

NS 7.0 was supporting
window.addEventListener("scroll", functionName, false)
much better than later releases:
http://bugzilla.mozilla.org/show_bug.cgi?id=35011#c64
http://bugzilla.mozilla.org/show_bug.cgi?id=189308
Opera 7 also had to fix a bug on this.

DU
 
S

Stephen Chalmers

Simon Wigzell said:
Can I trap when the scroll is ended? This is what I want - the calculator
disapears when the site visitor starts scrolling the main page. I'm doing
that with an "onScroll()" function. I'm bringing the calculator back with a
"onMouseup()" which I thoguht would activate when the scroll bar was
released but it doesn't. What I really want is an "offScroll()" but there is
no such thing!

http://www.mississippiprinting.com/...ES&PRODUCT=Full Color Brochure&PageSize=8 x 9

Nothing to stop it being 'simulated'. Try this - it even has a bandage for
Netscape 4, which doesn't
even have an onscroll event:

<HTML>
<HEAD>
<style>
..slider{position:absolute;left:20; top:10; border-style:ridge;
border-color:#0000ff; border-width:4px;

background-color:#000080; color:#ffffff; padding:10px; font-weight:bold}
</style>
</HEAD>

<BODY>

<DIV class=slider ID=slide>
Scroll the page & I will hide and stay hidden until the page stops.
</DIV>

<SCRIPT>
// (C)S Chalmers

var delay=null, dr=getDivRef('slide'), oldVPos=0, scrollInt=null;

function getVPos()
{
var v;
return (v=window.pageYOffset)!=undefined ? v :
((v=document.body.scrollTop)!=undefined ? v: 0) ;
}

function moveDiv(dRef)
{
var v=getVPos()

if(dRef)
{
dRef.visibility='hidden';

clearTimeout(delay);

delay=setTimeout("getDivRef('slide').visibility='visible'",800);

dRef.top=v+10;
}
}

function getDivRef(divId)
{

return document.getElementById
?
document.getElementById(divId).style
:document.layers
?
document.layers[divId]
:document.all
?
document.all(divId).style
:null;

}

scrollInt=setInterval("if(oldVPos!=getVPos()){oldVPos=getVPos();moveDiv(dr)}
",200); //NN4 fix

window.onscroll=function()
{
if(scrollInt!=null)
{
clearInterval(scrollInt);
scrollInt=null;
}
moveDiv(dr);
};

//// Page filler only - REMOVE ////
for(var i=0;i<200;i++)
document.write("|<BR>-<BR>");
///////////////////////////////////////
</SCRIPT>

</BODY>
</HTML>
 
R

Richard Cornford

Stephen Chalmers wrote:
... - it even has a
bandage for Netscape 4, which doesn't
even have an onscroll event:

Fair enough.

function getVPos()
{
var v;
return (v=window.pageYOffset)!=undefined ? v :

But a runtime error ("undefined is undefined") on IE4.
((v=document.body.scrollTop)!=undefined ? v: 0) ;
<snip>

And no support for IE 6 in standards mode.

Richard.
 
S

Stephen Chalmers

And no support for IE 6 in standards mode.
The OP's site wasn't selecting standards mode, which is difficult to support
for the purposes of setting a div's position. Mozilla requires a string
parameter, including 'px', while Netscape 4 at least, requires an integer.
 
S

Stephen Chalmers

Richard Cornford said:
The CSS units problem is not at all difficult to handle:-

<URL: http://jibberingg.com/faq/faq_notes/misc.html#mtCSSUn >
OK, but another pitfall is that Mozilla doesn't update
document.documentElement.scrollTop, so it's just as well that
window.pageYOffset is still available as it must be used instead.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 strict//EN">
<HTML>
<HEAD>
<style>
..slider{position:absolute;left:30px; top:20px; border-style:ridge;
border-color:#0000ff; border-width:4px;
background-color:#000080; color:#ffffff; padding:10px; font-weight:bold}
</style>
</HEAD>

<BODY>

<DIV class=slider ID=slide>
Scroll the page & I will hide until the page stops.
</DIV>

<SCRIPT>
// (C)S Chalmers

function vPosData()
{
this.index=0;
this.v=0;

if( typeof(window.pageYOffset)!='undefined' ) //must test first
this.index=3;
else
if( typeof(document.body.scrollTop)!='undefined' )
this.index=( document.compatMode &&
document.compatMode.indexOf("CSS")==0 ) ? 1 : 2;

this.getVPos();
}

vPosData.prototype.getVPos=function()
{
switch(this.index)
{
case 3: this.v=window.pageYOffset; break;
case 2: this.v=document.body.scrollTop; break;
case 1: this.v=document.documentElement.scrollTop; break;
case 0: this.v=0;
}

return this.v;
}

var stopWait=null, dr=getDivRef('slide'), scrollPeriod=null, vp=new
vPosData(), oldVPos=vp.v;

function moveDiv(dRef)
{
if(dRef)
{
dRef.visibility='hidden';

clearTimeout(stopWait);

stopWait=setTimeout("getDivRef('slide').visibility='visible'",800);

dRef.top=20+vp.getVPos()+(typeof(dRef.top)=='string'?'px':0);
}
}

function getDivRef(divId)
{
return document.getElementById
?
document.getElementById(divId).style
:document.layers
?
document.layers[divId]
:document.all
?
document.all(divId).style
:null;
}

scrollPeriod=setInterval("if(oldVPos!=vp.getVPos()){oldVPos=vp.getVPos();mov
eDiv(dr)}",200); //NN4 fix

window.onscroll=function()
{
if(scrollPeriod!=null)
{
clearInterval(scrollPeriod);
scrollPeriod=null;
}
moveDiv(dr);
};


//// Line generator only - REMOVE ////
for(var i=0, repeatCount=100/document.location.href.length;
i<repeatCount;i++)
for(var j=0; j<document.location.href.length;j++)
document.write(document.location.href.charAt(j)+"<BR>");
///////////////////////////////////////
</SCRIPT>

</BODY>
</HTML>
 
R

Richard Cornford

Stephen said:
OK, but another pitfall is that Mozilla doesn't update
document.documentElement.scrollTop, so it's just as well that
window.pageYOffset is still available as it must be used instead.

Opera 7, Konqueror 3, Safari 1, IceBrowser 5 and others don't either so
pageX/YOffset should be preferred (and is widely supported outside IE
browsers):-

<URL:
http://jibberingg.com/faq/faq_notes/not_browser_detect.html#bdScroll >

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top