1. 程式人生 > >scrollIntoView將指定元素定位到瀏覽器頂部,底部,中間

scrollIntoView將指定元素定位到瀏覽器頂部,底部,中間

lint pan lock col code .get near view res

var element = document.getElementById("box");
 
element.scrollIntoView();//頂部
element.scrollIntoView(false);//底部
element.scrollIntoView({block: "end"});
element.scrollIntoView({behavior: "instant", block: "end", inline: "nearest"});

scrollIntoView將指定元素定位到瀏覽器頂部,底部,中間