我正在尝试从我的剑道网格收集scrollLeft/scrollTop 位置数据。到目前为止我有这个:
var mainGrid = $("#mainGrid").data("kendoGrid");
var testgrid = $("#mainGrid div.k-grid-content");
topoffset = testgrid.offset();
//which gives me these numbers but they do not look correct...
//left 44.959999084472656 Number
//top 174.55999755859375 Number
然后我想通过强制网格滚动到顶部:0 和左侧:0 来演示自动定位。然后回到我用此捕获的位置...
//send to top
testgrid.scrollTop(0);
testgrid.scrollLeft(0);
Grid doesn't scroll to top as expected.
//send to previous position
testgrid.scrollTop(topScroll);
testgrid.scrollLeft(leftScroll);
Grid doesn't scroll back to previous position.
似乎不允许您强制滚动到剑道网格中的某个位置。
最佳答案
首先,您需要将其添加到数据绑定(bind)事件中。因此,如果您想提前设置它,您可以这样做:
databound: function(e){
$('.k-grid-content').scrollTop('150');
setTimeout(function () {
$('.k-grid-content').animate({
scrollTop: 0
}, 1000);
}, 2000);
setTimeout(function () {
$('.k-grid-content').animate({
scrollTop: 200
}, 1000);
}, 5000);
});
只需将值切换为您想要的滚动速度和距离(我刚刚使用了scrollTop,但您可以使用变体)。如果您想先使用网格然后捕获它所在的位置,请使用:
然后使用 sessionStorage 变量保存它,然后将其输入到数据绑定(bind)事件中。要在刷新之前捕获网格的位置,您可以执行以下操作:
$(document).on('keydown', function(){
$('.k-grid-content').scrollTop(); // capture how far from top
$('.k-grid-content').scrollLeft(); // capture how far from left
});
这不需要出现在您的数据绑定(bind)事件中。
关于javascript - 如何获取剑道网格的滚动位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46917284/