首页 > 解决方案 > 如何获取内联 css 溢出-y:自动效果的 Scrolltop() 值

问题描述

div 看起来像这样

<div class="nestedDemo" ng-include="'test.html'" style="height: 500px; 
 overflow-y: auto;"></div>

我想获取此 div 的 scrolltop 值,因为在将其他 div 添加到它(拖放功能)后,该 div 具有滚动条。

Js 代码看起来是这样的,但是即使有可用的滚动条,scrollValue 的值也始终为 0。

var scrollValue = $('.nestedDemo').scrollTop();

标签: javascriptjquery

解决方案


var scrollValue = $('.nestedDemo').scrollTop();
//the value is never change;
//when the div has scrollbar after adding other div's to it(drag-drop function).
//you need get the value once again. 
// if you remove a children , get the value once again . 

推荐阅读