~~SLIDESHOW~~
Lecture 10: To be given on Monday 7th March, 2011.
Lecturer: Dr Chris P. Jobling.
A dynamic HTML document is one whose tag attributes, tag contents, or element style properties can be changed after the document has been and is still being displayed by a browser
Informally, a dynamic XHTML document is one that in some way can be changed while it is being displayed by a browser. The most common client-side approach to providing dynamic documents is with JavaScript. Changes to documents can occur when explicitly requested by user interactions, or at regular timed intervals.
This lecture is based on Chapter 6 of Robert W. Sebasta, Programming the World-Wide Web, 3rd Edition, Addison Wesley, 2006. with additional material from Chapter 8 of Chris Bates, Web Programming: Building Internet Applications, 3rd Edition, John Wiley, 2006.
You should review the notes on CSS for layout before you dive into this lecture.
An introduction to Dynamic HTML
Reacting to the mouse
At the end of this lecture you should be able to answer these questions:
visibility
property? At the end of this lecture you should be able to answer these questions:
z-index
property? z-index
property to a large number or a small number? At the end of this lecture you should be able to answer these questions:
clientX
and clientY
properties after a mouse click? screenX
and screenY
properties after a mouse click? setTimeout
function. position
is set to either absolute
or relative
, the element can be moved after it is displayedtop
and left
property values with a script<source http://www.cpjobling.me/eg-259/examples/lecture10/mover.html javascript|mover.html>
visibility
property of an element controls whether it is displayedvisible
and hidden
if (dom.visibility == "visible") dom.visibility = "hidden"; else dom.visibility = "visible";
<source http://www.cpjobling.me/eg-259/examples/lecture10/showHide.html javascript|showHide.html>
backgroundColor
propertycolor
property:<note> Background color:
<input type = "text" size = "10" name = "background" onchange = "setColor('background', this.value)">
this
is a reference to the text box (the element in which the call is made) this.value
is the name of the new colour </note>
<source http://www.cpjobling.me/eg-259/examples/lecture10/dynColors.html javascript|dynColors.html>
onmouseover = "this.style.color = 'blue'; this.style.font = 'italic 16pt Times';" onmouseout = "this.style.color = 'black'; this.style.font = 'normal 16pt Times';"
<source http://www.cpjobling.me/eg-259/examples/lecture10/dynLink.html html|dynLink.html>
<source http://www.cpjobling.me/eg-259/examples/lecture10/dynValue.html javascript|dynValue.html>
z-index
attribute determines which element is in front and which are covered by the front element z-index
attribute is zIndex
z-index
can be changed dynamically (by changing zIndex
) onclick
attribute, so images can be clicked to trigger event handlershref
attribute can be set to call a JavaScript function by assigning it the call, with 'javascript'
attached to the call code <a href = "javascript:fun()">
zIndex
property value of the element<source http://www.cpjobling.me/eg-259/examples/lecture10/stacking.html javascript|stacking.html>
zIndex
value of the new top element to 10 and the zIndex
value of the old top element to 0 clientX
and clientY
properties of the event
objectscreenX
and screenY
are relative to the upper left corner of the whole client screenonclick
event<source http://www.cpjobling.me/eg-259/examples/lecture10/where.html javascript|where.html>
onmousedown
and onmouseup
that change the visibility attribute of the message <source http://www.cpjobling.me/eg-259/examples/lecture10/anywhere.html javascript|anywhere.html>
setTimeout("fun()", n)
onload
attribute of the body element to initialize the position of the element move
function to change the top and left attributes by one pixel in the direction of the destination "150px"
) <note>
<
and --
)CDATA
section </note>
<source http://www.cpjobling.me/eg-259/examples/lecture10/moveText.html html|moveText.html>
<source http://www.cpjobling.me/eg-259/examples/lecture10/moveTextfuns.js javascript|moveTextfuns.js>
mousedown
, mousemove
, and mouseup
events to grab, drag, and drop respectivelyleft
and top
properties Event
object and its property, currentTarget
)mousedown
handler, grabber
)<source http://www.cpjobling.me/eg-259/examples/lecture10/dragNDrop.html javascript|dragNDrop.html>
onmousedown
) while the mouse cursor is over the element to be movedcurrentTarget
property of the event
object top
and left
properties of the element as the mouse cursor is moved (onmousemove
)left
and top
values) and the mouse click position (clientX
and clientY
) An introduction to Dynamic HTML
Reacting to the mouse
At the end of this lecture you should be able to answer these questions:
visibility
property? z-index
property? z-index
property to a large number or a small number? At the end of this lecture you should be able to answer these questions:
clientX
and clientY
properties after a mouse click? screenX
and screenY
properties after a mouse click? setTimeout
function. Write, test, validate, and debug (if necessary) the following documents:
20em
wide). A light-grey image of yourself must be superimposed over the centre of the text as a nested element. Write, test, validate, and debug (if necessary) the following documents:
Write, test, validate, and debug (if necessary) the following documents:
More Dynamic HTML exercises, taken from Chapter 6 of Chris Bates, Web Programming: Building Internet Applications, 3rd Edition, John Wiley, 2006., are available.
JavaScript Libraries