Use jQuery to Detect Container Overflow?

前端 未结 5 862
萌比男神i
萌比男神i 2020-12-01 13:34

I\'ve seen this question but feel like there has to be a \"cleaner\" jQuery method of doing this. I\'m not even sure if this really works in all scenarios. Is there a way fo

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-01 14:07

    There exists another solution, (this example tests if the height overflows) it requires the overflowing container to be position:relative:

    HTML

    Javascript

         var last = $('.children:last'), container=$('#overflowing-container')
             lastOffsetHeight = container.scrollTop() + last.outerHeight(true) + last.position().top;
    
         if (last[0] && lastOffsetHeight > container[0].getBoundingClientRect().height) {
           console.log("thisContainerOverflows")     
         }
    

提交回复
热议问题