spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column73


Netscape 6, Part II: Animation

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

Moving Objects Horizontally

One of the trickiest task in DHTML is to move objects on the screen, browser-independently. Let's focus on the horizontal location of an object, usually associated with the word left. Netscape Navigator uses the left property of an element. Internet Explorer uses the pixelLeft property of the style object property. Netscape 6 uses the W3C Standard's left property of the style object property. Since Internet Explorer 5+ supports this property as well, we can use the following browser-independent code to move objects horizontally:

<FORM>
<INPUT ID="counter1" STYLE="position:relative; left:0px" TYPE="button" VALUE="Move Button" 
onclick="document.getElementById('counter1').style.left = '500px';">
</FORM>

That renders like this:

Click the button and see it moving to the right 500 pixels. Notice that the measurement (500) is specified with its units of measure (pixels). If you try to drop the px, you will get the same behavior, but it is not W3C/DOM compliant. Here is the HTML above without px:

<FORM>
<INPUT ID="counter2" STYLE="position:relative; left:0" TYPE="button" VALUE="Move Button" 
onclick="document.getElementById('counter2').style.left = 500;">
</FORM>

And you can play with it as well:

Next: How to move objects vertically

http://www.internet.com


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: December 18, 2000
Revised: December 18, 2000

URL: http://www.webreference.com/js/column73/4.html