spacer

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

home / programming / javascript / jf / column2 / 1 current pageTo page 2
[next]

Web Project Manager
Aquent
US-PA-Collegeville

Justtechjobs.com Post A Job | Post A Resume
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Synchronized Frame Scrolling Part 1: Vertical Scrolling

By Jonathan Fenocchi.

Have you ever needed to vertically scroll two frames at once, using one scrollbar? In this article, you’ll learn how to set up two frames, and how to get them to “synchronize” vertically. This may be especially useful for those who have designed web sites with a Flash interface or similar sites.

The first thing we need to do is set up our HTML. It’s going to be three simple pages: the main frame (fscroll_main.html), the left frame (fscroll_left.html), and the right frame (fscroll_right.html). The left and right frames’ source code should be simple HTML documents. Give them a scrollbar by putting STYLE=”height: 800%;” in a <DIV> tag in your HTML code. As for the fscroll_main.html page, the code is as follows:

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”>
<HTML>
<HEAD><META HTTP-EQUIV=”Content-Type” CONTENT=”text/html; charset=UTF-8”>
<TITLE>Vertical Synchronization with Frames</TITLE>
<SCRIPT type="text/JavaScript">
var sys = "document.body.scrollTop";
</SCRIPT></HEAD>
<FRAMESET id="fscroll" name="fscroll" cols="150,*">
<FRAME src="fscroll_left.html" name="left" id="left">
<FRAME src="fscroll_right.html" name="right" id="right">
</FRAMESET>
<BODY>
<P>Your browser does not support frames. Please download the latest version of your current browser, or get a new one, to view this site.</P>
</HTML>

It’s a relatively basic frameset page. Keep in mind the ID’s of the frames, as we’ll need them later on. The most notable object in this document is what the article is about – the variable sys will give us access to the amount of pixels the document is scrolled from the top of the page on either frame. This way, we can determine where to move the opposite frame when one frame is scrolled, and how far to move it.

At first, both your fscroll_left.html and fscroll_right.html pages should look like this:

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”>
<HTML>
<HEAD><META HTTP-EQUIV=”Content-Type” CONTENT=”text/html; charset=UTF-8”>
<TITLE>Frame</TITLE>
</HEAD>
<BODY>
<DIV STYLE=”height: 800%;”><P>This is a paragraph of text, so we don’t have a blank page!</P></DIV>
</BODY></HTML>

For testing purposes, this will create a vertical scrollbar on the page. Next, place a JavaScript tag in the heading of your left frame, and we’ll begin with the code.

var _run; // set a global variable with a null value. The null value will act as a Boolean false value.

if(navigator.userAgent.indexOf("Firebird")!=-1||navigator.appName=="Microsoft Internet Explorer")
{_run=false;}
else {_run= true;}

/* In the above lines of code, we’re checking to make sure the person is using either Mozilla FireBird or Microsoft Internet Explorer. We’ll set our global variable to false if they are using it, or set it to true in the event that someone is using Netscape or Opera (or some other unpopular browser). This variable will tell us which function to run. */

function vScroll() // begin function
{
var top = (window.pageYOffset)?(window.pageYOffset):(document.documentElement)?document.documentElement.scrollTop:document.body.scrollTop;

home / programming / javascript / jf / column2 / 1 current pageTo page 2
[next]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
  Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Fixing MySQL Replication · Firewall Guide: First Steps to Securing the Enterprise · VoxOx Tames the Tumultuous Communications Tangle

Created: June 5, 2003
Revised: January 14, 2004

URL: http://webreference.com/programming/javascript/jf/column2/1