jquery: 偏移量计算

解决carousel获取偏移问题,此处获取元素之前的距离偏移量:

carouselListItems.each(function (index) {
            $(this).click(function () {
                let itemOffset = parseInt($(this).offset().left);
                let wrapOffset = parseInt($('#carouselContainer').offset().left);
                let newLeft = itemOffset - wrapOffset;
                carouselCurrent.css('left', newLeft);
                showCurrentCarousel(index);
            });
        });

获取相对于可视窗口的左偏移量:

$('#elementId').offset().left

获取相对于已经定位的父元素左偏移量:

$('#elementId').position().left
原文地址:https://www.cnblogs.com/Nyan-Workflow-FC/p/13202384.html