Javascript jQuery-循环父div,获取最后一个子div的底部位置

Javascript jQuery-循环父div,获取最后一个子div的底部位置,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正在尝试循环父div并获取最后一个子div的底部位置 <main id="swipe-page"> <div class="dragend-page"> <div class="page-content"></div> <div class="page-content"></div> <div class="page-content"></div&g

我正在尝试循环父div并获取最后一个子div的底部位置

<main id="swipe-page">
    <div class="dragend-page">
        <div class="page-content"></div>
        <div class="page-content"></div>
        <div class="page-content"></div>
    </div>
    <div class="dragend-page">
        <div class="page-content"></div>
        <div class="page-content"></div>
    </div>
    <div class="dragend-page">
        <div class="page-content"></div>
        <div class="page-content"></div>
        <div class="page-content"></div>
        <div class="page-content"></div>
        <div class="page-content"></div>
    </div>
</main>

这是得到所有子div的底部位置,而不仅仅是最后一个。position函数肯定不正确,因为它返回的“this.position不是函数”

正如@Rudi在comments中提到的那样返回一个包含top和left属性的对象。。所以你可以用这个

$('.dragend-page').each(function(i, dragend_page) {
    var lastDiv = $(this).find('.page-content:last-child');
    var bottomPosition = lastDiv.position().top +  lastDiv.outerHeight(true);
    console.log(bottomPosition );

})

此代码将输出每个.dragend页面中最后一个.page内容的底部位置,因为@Rudi-inthecomments返回一个包含top和left属性的对象。。所以你可以用这个

$('.dragend-page').each(function(i, dragend_page) {
    var lastDiv = $(this).find('.page-content:last-child');
    var bottomPosition = lastDiv.position().top +  lastDiv.outerHeight(true);
    console.log(bottomPosition );

})

此代码将输出每个.dragend页面中最后一个.page内容的底部位置,因为@Rudi-inthecomments返回一个包含top和left属性的对象。。所以你可以用这个

$('.dragend-page').each(function(i, dragend_page) {
    var lastDiv = $(this).find('.page-content:last-child');
    var bottomPosition = lastDiv.position().top +  lastDiv.outerHeight(true);
    console.log(bottomPosition );

})

此代码将输出每个.dragend页面中最后一个.page内容的底部位置,因为@Rudi-inthecomments返回一个包含top和left属性的对象。。所以你可以用这个

$('.dragend-page').each(function(i, dragend_page) {
    var lastDiv = $(this).find('.page-content:last-child');
    var bottomPosition = lastDiv.position().top +  lastDiv.outerHeight(true);
    console.log(bottomPosition );

})
此代码将输出每个页面中最后一个页面内容的底部位置。dragend页面将为您提供最后一个div的位置,而不会在div中循环

$(function(){
    console.log($(".dragend-page :last-child").last().position());
});
将为您提供最后一个div的位置,而不通过div循环

$(function(){
    console.log($(".dragend-page :last-child").last().position());
});
将为您提供最后一个div的位置,而不通过div循环

$(function(){
    console.log($(".dragend-page :last-child").last().position());
});
将为您提供最后一个div的位置,而不通过div循环

$(function(){
    console.log($(".dragend-page :last-child").last().position());
});

页面内容:最后作为选择器。那么你也不需要每次打电话都打电话。Position是正确的函数,但是在each中,您需要执行$(this),因为它是一个jQuery函数而不是Dom函数。并且this.Position()应该是$(this.Position()Try.page content:last作为选择器。那么你也不需要每次打电话都打电话。Position是正确的函数,但是在each中,您需要执行$(this),因为它是一个jQuery函数而不是Dom函数。并且this.Position()应该是$(this.Position()Try.page content:last作为选择器。那么你也不需要每次打电话都打电话。Position是正确的函数,但是在each中,您需要执行$(this),因为它是一个jQuery函数而不是Dom函数。并且this.Position()应该是$(this.Position()Try.page content:last作为选择器。那么你也不需要每次打电话都打电话。Position是正确的函数,但在each中,您需要执行$(this),因为它是一个jQuery函数而不是Dom函数。而this.Position()应该是$(this)。Position()返回一个包含top和left属性的对象。@Rudi谢谢。。我更新了我的回答谢谢@Mohamed Yousef。然后我加上$(这个).height(p);更改父级高度,但在移动到下一张幻灯片时不会更改$(“#滑动页面”).dragend({afterInitialize:function(){this.container.style.visibility=“visible”;},onswipend:function(){var next_slide=parseInt(this.page)+1;window.location.hash=“slide=“+next_slide;$('.dragend page')。每个(函数(i,dragend页面){var lastDiv=$(this)。查找('.page content:last child');var p=lastDiv.position().top+lastDiv.outerHeight(true);$(this.height(p);}}}});@Studed我认为您需要运行该代码两次..一次在onsweepend中,一次在$(document.ready()之后..我的意思是尝试在.dragend之外使用该代码({返回一个包含top和left属性的对象。@Rudi Thank..我更新了answerThank@Mohamed Yousef。然后我添加$(this).height(p);以更改父级高度,但在移动到下一张幻灯片时它不会更改。$(“#滑动页面”).dragend({afterInitialize:function(){this.container.style.visibility=“visible”;},onswipend:function(){var next_slide=parseInt(this.page)+1;window.location.hash=“slide=“+next_slide;$('.dragend page')。每个(function(i,dragend_page){var lastDiv=$(this)。查找('.page内容:最后一个子项');var p=lastDiv.position top+lastDiv.outerHeight(true);$(this)。高度(p);})@Stiped我想你需要运行两次代码..一个在onsweepend中,一个在$(document).ready()之后..我的意思是尝试在.dragend({返回一个包含top和left属性的对象。@Rudi谢谢..我更新了我的答案Thank@Mohamed Yousef.然后我添加$(this).height(p);更改父级高度,但在移动到下一张幻灯片时不会更改。$(“#滑动页面”).dragend({afterInitialize:function(){this.container.style.visibility=“visible”;},onsweepend:function(){var next_slide parseInt(this.page)+1;window.location.hash=“slide=“+next#slide slide;$('.dragend page')。每个(函数(i,dragend_page){var lastDiv=$(this).find('.page content:last child');var p=lastDiv.position().top+lastDiv.outerHeight(true);$(this.height(p);}}}});@studed我认为您需要运行该代码两次..一次在onsweepend中,一次在$(document.ready()之后…我的意思是尝试在.dragend之外使用该代码({返回一个包含top和left属性的对象。@Rudi谢谢..我更新了answerThank@Mohamed Yousef。然后我添加$(this).height(p);以更改父级高度,但在移动到下一张幻灯片时它不会更改。$(“#滑动页面”).dragend({afterInitialize:function(){this.container.style.visibility=“visible”;},onsweepend:function(){var next_slide=parseInt(this.page)+1;window.location.hash=“slide=“+next_slide;”('.dragend page')。每个函数(i,dragend page){var lastDiv=$(this.find('.page content:lastDiv');var p=lastDiv.position.top+lastDiv.outerHeight(true);$(this.height(p);}}}});@Stiped我认为您需要运行该代码两次..一次在onsweepend中,一次在$(document.ready()之后..我的意思是尝试在.dragend之外使用该代码({