Skip to content

Elementoffset scroll to the center of the element #29

@cvalues

Description

@cvalues

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions