Move object with another element position on the screen with clientX

Asked

Viewed 373 times

0

I have the following code which is functional in IE7

function ScrollControl()
{
    var obj = window.event.srcElement;
    var evento = obj.componentFromPoint(event.clientX,event.clientY);
    window.div_cabecalho.scrollLeft = obj.scrollLeft;
}

The same code reads the movement of a table at the time of the scroll and moves the table header at the same time. The code does not work in other browsers, I tried with combinations of pageX but I can not get values at the time of movement

Jsfiddle

  • The problem is not in "obj", with the same value that IE returns in other browsers, my problem is with "Event.clientX,Event.clientY". With an Alert IE returns the numeric position, in the other browsers returns undefined.

  • You can do a jsFiddle with the problem so we can test?

  • This problem occurs because "normal" browsers do not use window.event but rather the event passed as argument in a function. If you show more code I can help fix this.

  • At a glance in that event reference scroll of a "normal" browser. And give more details about your problem, because with the existing information it is a little difficult to help.

  • I have a div with a table and with the attribute onscroll="Scrollcontrol() which in theory would run the Scrollcontrol function and make the table header move together with the table scroll.

  • I edited and posted the code in jsfiddle

Show 1 more comment

1 answer

1

Fixed using jquery

$('#div_grid').on('scroll', function () {
 $('#div_cabecalho').scrollLeft($('#div_grid').scrollLeft());
});
  • 1

    A better explanation of how it solved the problem would be very good.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.