Scott Mercer

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromScott Mercer
ToMe
SubjectLooping problem with a scrolling script
Date27 May 2004 04:18
Attachmenta page with an auto-pan script that was not working properly
Hi
 
I am having a problem with a script for making the window to scroll
depending on where the mouse is on the screen, (move mouse up and it
scrolls up, move mouse down and it scrolls down, same for left and right) I
got it to scroll as long as the mouse is moving. I want this code to make
the window to keep scrolling, whereas before the window will only scroll
when you are moving the mouse (for mousemove). So I desided to put in the
function name at the bottom so that it would repeat the process. but the
side effect is that it goes too fast and if you have the window smaller it
closes the browser when you move the mouse into a scroll spot after getting
to the end of scrolling. (may do it before the end of scrolling)

 
anyway I have put the script and a sample page in an attachment.
 
you can put this script on your website if you want. I am designing it for
when the user loads a page that has a large picture and has to scroll to
ee the whole thing.
 
you may recignise some of your coding that is in the script from this page:
 
http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
 
also with your web site, I find there are alot of errors (one per page) on
each refresh/onload. am using sleipnir 1.41 (renders almost the same as IE6)
FromMe
ToScott Mercer
SubjectRe: Looping problem with a scrolling script
Date27 May 2004 15:21
Attachmenta script that produces the desired functionality
Scott,

Firstly, are you aware that most three button mice or scrollwheel mice can
autopan when the middle button or scroll wheel is clicked? That produces an
effect exactly like the one you want.

I feel you may have been looking at this problem from the wrong angle.
Instead of telling it to move when the mouse moves, tell it to move to a
new position every 0.n seconds (using a setInterval timer). If you have
registered any mouse movements, then store them, and use them to calculate
where to scroll to.

To get the resizing to work properly, all you need to do is sample the
window size every time the mouse moves. Then the stored position will
always be relative to the correct window size.

Note that the mouse position includes scrolling in some browsers, so this
needs to be subtracted.

There is another problem that is very difficult to avoid. When they move
their mouse outside the page area, the script will still think they are
over it (onmouseout on the page does not work properly), so it will
continue to scroll. I put a dead area outside the scroll area, although if
they move their mouse reaaly fast, you won't see it. I would suggest doing
this anyway, and just hoping it does not happen too often. Besides, you can
use your button to toggle if it should/should not auto-scroll, and that
should be enough.

Fortunately, if you use scrollBy, the browser will automatically stop you
if you go too far, so there is no need to know document size, just window
size.

I have attached a script that does this.

Hope this helps


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromScott Mercer
ToMe
SubjectRe: Looping problem with a scrolling script
Date28 May 2004 03:37
Thanks Mark,

You must be clever to have done all that in two days!!! At first had to
work out how to make it work in an external file. So I put it in the
html file itself and it worked. Then I tried to use the external file
again but this time I changed the location of the function line so it is
now at the top and it works from an external file. Now I only just have
to work out how to make it work with a cookie. I am new to JavaScript.

One more question, if I had a link for a CSS so that browsers with no
JavaScript could use, could I have JavaScript overwrite the link so that
there is a way to accommodate different screen resolutions?

I noticed you fixed your web site up from those bugs.

You said on your website that you get a lot of spam. How come you have
not cloaked your email address with a JavaScript?

Like this one:

[a long-winded JavaScript that writes an email address link]

Thanks again mark.

Yours Sincerely


Scott Mercer
FromMe
ToScott Mercer
SubjectRe: Looping problem with a scrolling script
Date28 May 2004 08:31
> Thanks Mark,

no problem :)

> You must be clever to have done all that in two days!!!

Erm, 30 minutes **cough**.

I had written most of the components of the script already, so it was a
simple case of putting them together, and then adding on the 'how much
scould I scroll' section.

> I tried to use the external file

With the script I sent you, it should not matter where in your document you
put it, but I would recommend between the <head> tags:

<script type="text/javascript" src="path/to/AutoScroll.js"></script>

> Now I only just have to work out how to make it work with a cookie.

Why do you need to use autoscroll with cookies? cookies are used to store
information between pages. What information were you planning to store?

Note, I have written a full cookie management script that you are free to
use:
http://www.howtocreate.co.uk/jslibs/

> One more question, if I had a link for a CSS so that browsers with no
> JavaScript could use, could I have JavaScript overwrite the link so that
> there is a way to accommodate different screen resolutions?

yes. just make sure that you put the basic CSS first, then put the
resolution specific CSS later, or make it more specific (CSS specificity
cascading). That way, the CSS cascade takes care of the overriding.

<link rel="stylesheet" href="basic.css">
<script type="text/javascript"><!--
var cssLoc;
if( screen.width < 800 ) { cssLoc = 'style640'; }
else if( screen.width < 1024 ) { cssLoc = 'style800'; }
else { cssLoc = 'style1024'; }
document.write('<link rel="stylesheet" href="'+cssLoc+'.css">');
//--></script>

> I noticed you fixed your web site up from those bugs.

my website actually does not enforce any widths at all, it allows the
browser to use whatever width it has available.

> You said on your website that you get a lot of spam. How come you have
> not cloaked your email address with a JavaScript?

I have :) but I also have about several other email accounts coming into
the same mailbox. Unfortunately one of those receives a huge amount of spam
(because I did not realise it was a bad idea to put email addresses on web
pages when I started using the internet), and I would get rid of it, but
too many people use it legitimately.

> Like this one:

because that script does not allow people without script enabled to do
anything at all. With mine, they will get the email address, with some
extra stuff to stop it looking like an email address, and some instructions
on how to turn it back into one.

I have documented a more accessible (and mush smaller than that script) way
to do this on:
http://www.howtocreate.co.uk/tutorials/javascript/security#protectEmail
FromScott Mercer
ToMe
SubjectRe: cloaking email address without a script (user friendly)
Date28 May 2004 17:07
It says on your web site:

[without JavaScript enabled]
myEmailName(replace with @ symbol)myEmailDomain.com 
you do not have JavaScript enabled.

The noscript link requires you to
replace the section in brackets with an @ symbol.

>>>>What if I put in the following code:?

<a
href="mailto:&#115;&#109;&#101;&#114;&#99;&#101;&#114;&#64;&#116;&#115;&
#110;&#46;&#99;&#99;">
    
&#115;&#109;&#101;&#114;&#99;&#101;&#114;&#64;&#116;&#115;&#110;&#46;&#9
9;&#99;</a>


>>>>use it in a browser and it will link to my email address.

>>>>Question is: will it stop the spam bots from noticing it?

Something to think about.

Oh well last case option is to use the code for the @ symbol

&#64;
FromMe
ToScott Mercer
SubjectRe: cloaking email address without a script (user friendly)
Date28 May 2004 19:09
yeah, I have seen many people use this before. so far, I have not heard any
bad reports about this technique, but I worry that it will only be a matter
of time before spammers learn to regognise addresses in this format. After
all, they only need to use an entity translation table and they will have a
real address again. Perl (a very popular language that may well be used for
email address spidering) and PHP already offer dedicated ways to translate
entities into text. That is why I prefer the technique I use, since it
would require them to use a script engine, not just simple string
manipulation.
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.