Technology Programming

JavaScript By Example

In the previous example we saw how to create an object having a number of properties. In almost all cases we can create the properties directly when we create the object because we want each object to have its own properties.

There are several different ways of adding methods depending on whether we want the methods to be specific to that object or want them to be shared between objects.

In this example we add two methods to our $B to get the current X and Y coordinates of the mouse cursor within the web page.We add them in a way that makes them specific to this object because in this instance our $B object provides us with a standard way to interface with the browser itself and as there is only the one browser involved in any given display of the web page we will never need to create multiple objects of this type.



$B = {
sWidth: screen.availWidth,
sHeight: screen.availHeight,
width: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
height: window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
left: (window.pageXOffset>-1) ? window.pageXOffset : document.documentElement.scrollLeft || document.body.scrollLeft,
top:(window.pageyOffset>-1) ? window.pageyOffset : document.documentElement.scrollTop || document.body.scrollTop,
mouseX: function(evt) {var evt = window.event || evt; return evt.clientX ? evt.clientX + this.left : evt.pageX},
mouseY: function(evt) {var evt = window.event || evt; return evt.clientY ? evt.clientY + this.top: evt.pageX}

};

Related posts "Technology : Programming"

The Importance Of Having a WordPress Business Theme

Programming

Website Design Is Necessary For Your Website

Programming

The Most effective On line Paid Survey Evaluation

Programming

Adelaide SEO - Links And Keywords, How Should They Be Used

Programming

C Programming Compilers for Microcontrollers

Programming

How Should A DJ Make Music Logo That Is Distinct And Cool?

Programming

Call to Action Concepts for Small Businesses

Programming

Microsoft Access Databases in Office 365

Programming

Why web design is crucial for producing world class websites

Programming

Leave a Comment