Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass Event Object between frames.

Status
Not open for further replies.

jagi

Programmer
Mar 13, 2005
48
US
Hi,

I have two frames in a window. The 'onscroll' event of a DIV in one frame should cause an offset in the DIV element of the other frame.

frame1 -> div1 ( when scrolled should cause an offset in )
frame2 -> div2

In other words, I need to be able to synchronize DIVs in two different frames. I am using this function for synchronizing:


function getOnScrollFunction(oElement) {
return function () {
if (oElement._scrollSyncDirection == "horizontal" || oElement._scrollSyncDirection == "both")
oElement.scrollLeft = event.srcElement.scrollLeft;
if (oElement._scrollSyncDirection == "vertical" || oElement._scrollSyncDirection == "both")
oElement.scrollTop = event.srcElement.scrollTop;
};

}
// This function adds scroll syncronization for the fromElement to the toElement
// this means that the fromElement will be updated when the toElement is scrolled
function addScrollSynchronization(fromElement, toElement, direction) {

fromElement._syncScroll = getOnScrollFunction(fromElement);
fromElement._scrollSyncDirection = direction;
fromElement._syncTo = toElement;
toElement.attachEvent("onscroll", fromElement._syncScroll);
}


The problem is, the need to be able to pass the event object from to this script, as the DIVs are in two different frames. I am using iframes in this case.

How can I pass the onscroll event between objects ? Can anyone help?

Thanks.


 
you don't need to pass the event. simply set the scrollTop of the one div to the scrollTop of the other div.

Have the same function defined in both html pages, or include the same function in an external js file.

then, just use something like:

Code:
top.frames['otherFrameName'].getElementById('otherDivName').scrollTop = document.getElementById('thisDivName').scrollTop;

*cLFlaVA
----------------------------
[tt]a frickin' twelve-gauge, what do you think?[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top