0

I tried to set a paint apps in an slider show. Thus I need the active slide div position.

The position of the slide wrapper (div.slide) work fine without adding slide effect. Such as without slider.

But when I add the slider effect, the position goes wrong. As you can see with slider, the position show 1.[x:528 y:8], 2.[x:1048 y:8] and 3.[x:8 y:8].

I think it should always be [x:8 y:8] for every slide when it is active. The findPos function is as following

//Get the absolute position of a DOM object on a page
function findPos(obj) {
var curLeft = curTop = 0;
if (obj.offsetParent) {
    do {
        curLeft += obj.offsetLeft;
        curTop += obj.offsetTop;
    } while (obj = obj.offsetParent);
}
 return {x:curLeft, y:curTop};
}

Could someone give some hint? Thanks.

wilson Liu
  • 579
  • 2
  • 8
  • 18
  • The library uses `translate3d` to move the slides. You could try to use [Element.getBoundingClientRect()](https://developer.mozilla.org/en-US/docs/Web/API/element.getBoundingClientRect) `[...]Starting in Gecko 12.0, the effect of CSS transforms is considered when computing the element's bounding rectangle.[...]` – t.niese Jan 18 '15 at 14:29
  • Hi, thanks.I had tried the getBoundingClientRect method. [jsffidle](http://jsfiddle.net/vw3Loafj/3/), but the content 3 failed... – wilson Liu Jan 18 '15 at 14:51
  • Ok it works! thanks niese. [fixed](http://stackoverflow.com/questions/25630035/javascript-getboundingclientrect-changes-while-scrolling) – wilson Liu Jan 18 '15 at 15:08

0 Answers0