-
Notifications
You must be signed in to change notification settings - Fork 0
/
scroll-detect.html
68 lines (58 loc) · 1.41 KB
/
scroll-detect.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Scroll matching</title>
<style type="text/css">
#t1, .t1-info {
background: #cef;
}
#replace, .replace-info {
background: #fce;
}
#replace {
cursor: default;
}
#t1, #replace{
height: 100px;
padding: 0px 5px;
margin: 0;
border: 0;
width: 150px;
font-size: 1.0em;
line-height: 1.2em;
font-family: inherit;
white-space: pre-wrap;
overflow: auto;
}
</style>
<script type="text/javascript" src="jquery-1.4.js"></script>
<script type="text/javascript">
$(function(){
$('#replace').hide();
$('#replace, #t1').live('click', function(){
$me = $(this);
var theScrollTop = $me[0].scrollTop;
$me.hide();
if($me.attr('id')=='t1'){
$them = $('#replace').text($me.val()).show().focus();
} else {
$them = $('#t1').val($me.text()).show().focus();
}
// Main attraction:
$them[0].scrollTop = theScrollTop;
})
});
</script>
</head>
<body>
<h1>Scroll matching</h1>
<textarea name="textarea" id="t1" wrap="wrap">Some content
This should be long enough that you have to scroll to see all the content
Go ahead, try it — then click in this box. It will be replaced with a static div instead.
Click that.
Hopefully, it will always be scrolled to exactly the same place.</textarea>
<div id="replace"></div>
<p>The textarea is <span class="t1-info">blue</span> and the replaced, static div is <span class="replace-info">pink</span>.</p>
</body>
</html>