Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tour tooltip position inside elements with scroll is wrong #210

Closed
samiracho opened this issue Oct 7, 2013 · 12 comments
Closed

Tour tooltip position inside elements with scroll is wrong #210

samiracho opened this issue Oct 7, 2013 · 12 comments
Assignees
Labels

Comments

@samiracho
Copy link

samiracho commented Oct 7, 2013

The way the offsets are calculated doesnt work if the element is inside another element with scroll. I fixed it changing _getOffset function and using "getBoundingClientRect" function (more reliable than the while loop approach)

function _getOffset(element) {
    var elementPosition = {};

    //set width
    elementPosition.width = element.offsetWidth;

    //set height
    elementPosition.height = element.offsetHeight;

    //calculate element top and left
    /* ( Comment old way to get the offsets )
    var _x = 0;
    var _y = 0;
    while (element && !isNaN(element.offsetLeft) && !isNaN(element.offsetTop)) {
        _x += element.offsetLeft;
        _y += element.offsetTop;
        element = element.offsetParent;
    }
    //set top
    elementPosition.top = _y;
    //set left
    elementPosition.left = _x;
    */

    var clientRect = element.getBoundingClientRect();
    elementPosition.top = clientRect.top;
    elementPosition.left = clientRect.left;

    return elementPosition;
}
@roine
Copy link

roine commented Feb 5, 2014

I was having a problem with the position and your code solved it. Thanks!

@peterburjan
Copy link

This fix worked for me as well, thank you. Is there any plans to get this merged in?

@Daveslow
Copy link

This worked for me as well. I've had to make 3 changes outlined in bug reports to get the framework working properly. Can we get these things merged in?

@leejordan
Copy link

I think this would also solve the problem with helperLayer positioning being incorrect when the parent has a border as offsetParent does not seem to take borders into account.

@vinicius-camara
Copy link

It's better people start with x and y 0 in position.
Only with this way is possible start the app tour.

//start top of application
window.scrollTo(0,0);
var elementPosition = {};

@alexmgrant
Copy link

🍻

@c-johnson
Copy link

+1, any canonical answer for this? I had to combine this with the fix described in #350 to get this to work in my application

c-johnson pushed a commit to c-johnson/intro.js that referenced this issue Sep 10, 2015
@c-johnson
Copy link

I'm hosting a fork of this at https://github.com/c-johnson/intro.js/blob/master/intro.js if anybody needs to use this as a temporary solution. Combining with #350 above gives me the solution I want. It looks like this possibly addresses concerns raised in #182. Again, this alone didn't fix my problem, I had to combine with manual scrolling behavior to get it to work

@mwager
Copy link

mwager commented Dec 17, 2015

Same problem here, any activity on this?

@scottwestover
Copy link

I was having the same issue, and your code worked fixed it. Thanks again for sharing it.

@halshing
Copy link

halshing commented Jun 6, 2017

I'm using IntroJS with SharePoint Online and was having this exact issue with scrolling to web parts that are further down the page. Replacing the _getOffset method with the one from @samiracho worked! But like @c-johnson mentioned, I had to also include code to force the scroll of the workspace container to the target element. Something like this:

var intro = introJs();
var workspace = document.querySelector("#s4-workspace");
intro.onbeforechange(function (targetElem) {
     workspace.scrollTop = targetElem.offsetTop - workspace.offsetTop;
});

Thanks everyone!

@bozdoz
Copy link
Collaborator

bozdoz commented Dec 12, 2017

I will take a look at this and see if I can get a PR ready for this and #350. Thanks for the help.

@bozdoz bozdoz self-assigned this Dec 12, 2017
@bozdoz bozdoz added the bug label Dec 12, 2017
sliceofbytes added a commit to sliceofbytes/intro.js that referenced this issue Feb 9, 2018
Scroll parent element to targetElement; resolves usablica#210; resolves usablica#350;
ipastushenko added a commit to ipastushenko/intro.js that referenced this issue Feb 15, 2018
Scroll parent element to targetElement; resolves usablica#210; resolves usablica#350;
@bozdoz bozdoz closed this as completed in b8cde24 Feb 23, 2018
bozdoz added a commit that referenced this issue Feb 23, 2018
Scroll parent element to targetElement; resolves #210; resolves #350; resolves #373
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests