我有一个场景,在刷新 Kendo Treeview 时,我需要将 View 滚动到树的第一项。
<body>
<div style="height: 500px; width: 200px; border:1px solid black;" id="tree"></div>
<div style=" margin:10px; display:block">
<button style="width:50px; height:20px;" onclick="clickMe()">Click</button>
</div>
<script>
// setup: generate data, select item
var data = [];
for (var i = 0; i < 1000; i++) {
data.push({ text: "Item " + i });
}
$("#tree").kendoTreeView({
dataSource: data
});
function clickMe() {
debugger;
var treeview = $("#tree").data("kendoTreeView");
treeview.select(treeview.findByText("Item 500"));
// scroll to selected item
var itemScrollTop = treeview.select()[0].offsetTop;
$("html,body").animate({ scrollTop: itemScrollTop });
}
</script>
</body>
我尝试使用上面的代码,但问题是它不起作用。如果我们删除 kendo Treeview div 的高度,那么它就可以工作。但我需要设置 Treeview 的高度。
如何在 Kendo Treeview 中滚动到顶部?
最佳答案
我尝试为tree
div而不是html和body设置动画。不确定这就是您要找的。
关于javascript - 滚动到 Kendo Treeview 的顶部节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42852281/