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

Elementoffset scroll to the center of the element #29

Open
cvalues opened this issue Oct 31, 2022 · 0 comments
Open

Elementoffset scroll to the center of the element #29

cvalues opened this issue Oct 31, 2022 · 0 comments

Comments

@cvalues
Copy link

cvalues commented Oct 31, 2022

Hi,

`
e.preventDefault();
var target = '.'+$(this).data('target');
var left = $(target).position().left;
var total = $('.front.scroll').width();
var perc = left / (total - $(window).width()) * 100;

    var height = $('html').height();
    var final = ((height - $(window).height())/ 100 * perc);

    $('html, body').animate({scrollTop: final}, 500);

`

Scrolls the selected item to the left corner.
How to scroll to the element center?

var perc = left / (total - ($(window).width()+ $(target).width)/2 ) * 100;

Does not do the trick
BR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant