Ari*_*rif 3 scroll tween d3.js
我有一个div,#scrollable,带滚动条,我想滚动到最后.我可以通过将div的"scrollTop"属性设置为div的"scrollHeight"属性的值来实现:
var scrollable = d3.select("#scrollable");
scrollable.property("scrollTop", scrollable.property("scrollHeight"));
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚,如果有的话,我可以补充它.
var scrollheight = scrollable.property("scrollHeight");
d3.select("#scrollable").transition().property("scrollTop", scrollheight);
Run Code Online (Sandbox Code Playgroud)
不起作用.
谢谢你的任何想法.问候
您可以使用自定义d3补间转换任意属性,如scrollTop.
mbostock的Smooth Scrolling示例演示如何使用自定义补间来滚动整个文档.
以下是适合您的上下文的示例(也可以在bl.ocks.org上以交互方式查看):
var scrollable = d3.select("#scrollable");
d3.select("#down").on('click', function() {
var scrollheight = scrollable.property("scrollHeight");
d3.select("#scrollable").transition().duration(3000)
.tween("uniquetweenname", scrollTopTween(scrollheight));
});
function scrollTopTween(scrollTop) {
return function() {
var i = d3.interpolateNumber(this.scrollTop, scrollTop);
return function(t) { this.scrollTop = i(t); };
};
}
Run Code Online (Sandbox Code Playgroud)