Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JavaScript设置HTML页面垂直位置_Javascript_Scroll_Position - Fatal编程技术网

使用JavaScript设置HTML页面垂直位置

使用JavaScript设置HTML页面垂直位置,javascript,scroll,position,Javascript,Scroll,Position,我有一个可以上下滚动的HTML页面(不是很多,但它确实可以滚动)。在执行一些JavaScript之后,如何设置页面中的滚动位置 我正在使用jQuery在页面底部插入一些额外的HTML,并且我希望在添加新内容后通过编程滚动到新内容的位置。尝试使用 例如: // put the 100th vertical pixel at the top of the window <button onClick="scroll(0, 100);">click to scroll down 100 p

我有一个可以上下滚动的HTML页面(不是很多,但它确实可以滚动)。在执行一些JavaScript之后,如何设置页面中的滚动位置

我正在使用jQuery在页面底部插入一些额外的HTML,并且我希望在添加新内容后通过编程滚动到新内容的位置。

尝试使用

例如:

// put the 100th vertical pixel at the top of the window
<button onClick="scroll(0, 100);">click to scroll down 100 pixels</button>
//将第100个垂直像素放在窗口顶部
单击可向下滚动100像素

另一种方法是这样做,以便您可以选择:

在要添加到页面底部的HTML中,可以插入一个命名的锚定标记,然后更改URL,使页面移动到那里(仅供参考:它不会刷新页面)

//像这样动态添加HTML:
// 
//使页面转到该位置的javascript:
window.location.hash=“moveHere”;
根据您正在做的事情,这可能是一个有用的解决方案,也可能不是

// add HTML like this, dynamically:
// <a name="moveHere" />

// the javascript to make the page go to that location:
window.location.hash = "moveHere";