yawnmoth wrote:
I'm trying to write a script whereby the body background is changed to
back (from white) when the mouse button is held down and kept held
down. When you lift it up, I'd like it to change back to white.
Unfortunately, I'm not sure how to do that. Any ideas? Here's my
code:
http://www.frostjedi.com/terra/scrip...mousedown.html
Now, that is so little code that you could have posted it, too:
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
You do not want to use XHTML. Use HTML 4.01 instead.
| <head>
| <title>onmoused own / onmouseup</title>
| </head>
|
| <body id="body">
The `body' element does not need an ID to be referred to.
| <script type="text/javascript">
| body = document.getEle mentById('body' );
`body' was not declared, which is error-prone. And you don't need the
additional identifier anyway:
document.body
is mostly standards-compliant:
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-62018039>
| document.onmous eup = body.style.back ground = '#fff';
| document.onmous edown = body.style.back ground = '#000';
It if works, this is assigning "#fff" to `document.onmou seup' and "#000" to
`document.onmou sedown' because the right-hand side of the whole assignment
evaluates to the result of the right-hand side assignment.
Because there is no delay in the evaluation of the right-hand side
assignment, the background color of the `body' element would turn white and
immediately black afterwards.
You should not use the `background' CSS property when all you want to do is
to change the background color.
The `onmouseup' and `onmousedown' properties are proprietary and should not
be used but as a fallback for the standards-compliant approach.
It is not necessary here to use scripting to define the event listeners; the
HTML BODY element (and the XHTML `body' element) has intrinsic event handler
attributes for that.
<body
onmouseup="docu ment.body.style .backgroundColo r = '#fff';"
onmousedown="do cument.body.sty le.background = '#000';">
(Usually, by convention you could refer to the handling element with `this',
but the `body' element has a peculiarity here.)
RTFM.
<http://jibbering.com/faq/>
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>