返回到:Prototype – 元素对象
此方法滚动窗口,使元素出现在视口的顶部。
这与使用HTML 锚点所达到的效果类似(除了不修改浏览器的历史记录)。
语法
element.scrollTo();
返回值
返回一个 HTML 元素。
例子
HTML
x
42
42
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function showResult() {
8
$('heading').scrollTo();
9
}
10
</script>
11
</head>
12
13
<body">
14
<h1 id = "heading">This is the heading.</h1>
15
<p id = "test">Click the button see the result.</p>
16
<p id = "test">Click the button see the result.</p>
17
<p id = "test">Click the button see the result.</p>
18
<p id = "test">Click the button see the result.</p>
19
<p id = "test">Click the button see the result.</p>
20
<p id = "test">Click the button see the result.</p>
21
<p id = "test">Click the button see the result.</p>
22
<p id = "test">Click the button see the result.</p>
23
<p id = "test">Click the button see the result.</p>
24
<p id = "test">Click the button see the result.</p>
25
<p id = "test">Click the button see the result.</p>
26
<p id = "test">Click the button see the result.</p>
27
<p id = "test">Click the button see the result.</p>
28
<p id = "test">Click the button see the result.</p>
29
<p id = "test">Click the button see the result.</p>
30
<p id = "test">Click the button see the result.</p>
31
<p id = "test">Click the button see the result.</p>
32
<p id = "test">Click the button see the result.</p>
33
<p id = "test">Click the button see the result.</p>
34
<p id = "test">Click the button see the result.</p>
35
<p id = "test">Click the button see the result.</p>
36
<p id = "test">Click the button see the result.</p>
37
<p id = "test">Click the button see the result.</p>
38
<p id = "test">Click the button see the result.</p>
39
40
<input type = "button" value = "Click" onclick = "showResult();"/>
41
</body>
42
</html>
返回到:Prototype – 元素对象
阅读剩余 56%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/9014.html