Java Reference
In-Depth Information
The new
direction
value is simple; you simply make
direction
negative. So if
direction
is
positive, it becomes negative. If
direction
is negative, it becomes positive (remember: a negative
times a negative is a positive).
You then calculate the new left position and change the element's style:
var newLocation = currentLeft + direction;
divAdvert.style.left = newLocation + "px";
Chapter 10
exercise 1 Question
Add a method to the event utility object called
isOldIE()
that returns a boolean value indicating
whether or not the browser is old‐IE.
exercise 1 Solution
var evt = {
addListener: function(obj, type, fn) {
if (typeof obj.addEventListener != "undefined") {
obj.addEventListener(type, fn);
} else {
obj.attachEvent("on" + type, fn);
}
},
removeListener: function(obj, type, fn) {
if (typeof obj.removeEventListener != "undefined") {
obj.removeEventListener(type, fn);
} else {
obj.detachEvent("on" + type, fn);
}
},
getTarget: function(e) {
if (e.target) {
return e.target;
}
return e.srcElement;
},
preventDefault : function(e) {
if (e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false;
}
},
isOldIE: function() {
return typeof document.addEventListener == "undefined";
}
};