Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

JavaScript floating objects

Nicholas Chase, Author, Web Site Developer
Nicholas Chase has been involved in Web site development for companies including Lucent Technologies, Sun Microsystems, Oracle Corporation, and the Tampa Bay Buccaneers. Nick has been a high school physics teacher, a low-level radioactive waste facility manager, an online science fiction magazine editor, a multimedia engineer, and an Oracle instructor. More recently, he was the Chief Technology Officer of Site Dynamics Interactive Communications in Clearwater, Florida. He is the author of three books on Web development, including Java and XML From Scratch (Que). He loves to hear from readers and can be reached at nicholas@nicholaschase.com.

Summary:  Have you ever seen content floating in the corner of your browser? Scroll the page, resize the window, and it still appears in that corner. This tutorial teaches you to create cross-browser floating content on a page, and even to reposition it.

Date:  20 Dec 2001
Level:  Introductory PDF:  A4 and Letter (810 KB | 45 pages)Get Adobe® Reader®

Activity:  7136 views
Comments:  

Before you start

About this tutorial

This tutorial is for Web developers who want to create objects, such as images and menus, that hold their place (or float) in the browser window even when the user scrolls or resizes the window.

The first floating objects seen on the Web were likely watermarks placed in a top or bottom corner of the browser to identify a Web community such as Geocities. These were semi-transparent and meant to be unobtrusive, but were nevertheless fascinating to users who had never seen an object that didn't move when they scrolled the page.

Objectives

Today, you can achieve the same effect using JavaScript in the browser -- creating content, placing it, and controlling its location as the user scrolls or resizes the page. This tutorial discusses the process necessary for creating these floaters in such a way that they are available to users of both Netscape (4.x and 6.x) and Microsoft Internet Explorer (5.x and 6.x) browsers.

In addition, this tutorial demonstrates how to allow Internet Explorer users to reposition the floater in such a way that it holds its new position even when the page is scrolled or resized.

Prerequisites

You should be generally familiar with HTML and JavaScript. An understanding of both dynamic positioning and objects is helpful, but not required; the basics are covered in this tutorial. (Find more information on these subjects in the Resources section at the end of this tutorial.)

System requirements

Example code snippets are provided throughout the tutorial to underscore the concepts discussed. To work through the examples, you need:

  • A text editor: HTML pages and the JavaScript sections within them are simply text. To create and read them, a text editor is all you need.
  • Any browser capable of exploiting dynamic positioning using JavaScript: This includes Netscape Navigator 4.7x and 6.1, and Microsoft Internet Explorer 5.5. Note that while this tutorial discusses creating floaters that work in all three of the above browsers, the floater can only be repositioned in IE 5.5.

1 of 9 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Web development
ArticleID=136470
TutorialTitle=JavaScript floating objects
publish-date=12202001
author1-email=
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Special offers