PageSourceSearch

https://www.renet.jp/js_new/smoothScroll.js

js renet.jp collected 2026-10-02 18:28:28 UTC 2,373 bytes, 98 lines download raw bytes

1/*--------------------------------------------------------------------------*
2 *  
3 *  SmoothScroll JavaScript Library V2
4 *  
5 *  MIT-style license. 
6 *  
7 *  2007-2011 Kazuma Nishihata 
8 *  http://www.to-r.net
9 *  
10 *--------------------------------------------------------------------------*/
11 
12new function(){
13
14	var attr ="data-tor-smoothScroll";//for html5 , if you can't use html5 , this value change "class"
15	var attrPatt = /noSmooth/;
16	var d = document;//document short cut
17	
18	/*
19	 *add Event
20	  -------------------------------------------------*/
21	function addEvent(elm,listener,fn){
22		try{ // IE
23			elm.addEventListener(listener,fn,false);
24		}catch(e){
25			elm.attachEvent(
26				"on"+listener
27				,function(){
28					fn.apply(elm,arguments)
29				}
30			);
31		}
32	}
33
34	/*
35	 *Start SmoothScroll
36	  -------------------------------------------------*/
37	function SmoothScroll(a){
38		if(d.getElementById(a.rel.replace(/.*\#/,""))){
39			var e = d.getElementById(a.rel.replace(/.*\#/,""));
40		}else{
41			return;
42		}
43		
44		//Move point
45		var end=e.offsetTop
46		var docHeight = d.documentElement.scrollHeight;
47		var winHeight = window.innerHeight || d.documentElement.clientHeight
48		if(docHeight-winHeight<end){
49			var end = docHeight-winHeight;
50		}
51		
52		//Current Point
53		var start=window.pageYOffset || d.documentElement.scrollTop || d.body.scrollTop || 0;
54		
55		
56		var flag=(end<start)?"up":"down";
57
58		function scrollMe(start,end,flag) {
59			setTimeout(
60				function(){
61					if(flag=="up" && start >= end){
62						start=start-(start-end)/20-1;
63						window.scrollTo(0,start)
64						scrollMe(start,end,flag);
65					}else if(flag=="down" && start <= end){
66						start=start+(end-start)/20+1;
67						window.scrollTo(0,start)
68						scrollMe(start,end,flag);
69					}else{
70						scrollTo(0,end);
71					}
72					return ;
73				}
74				,10
75			);
76			
77		}
78
79		scrollMe(start,end,flag);
80		
81	}
82
83	/*
84	 *Add SmoothScroll
85	  -------------------------------------------------*/
86	addEvent(window,"load",function(){
87		var anchors = d.getElementsByTagName("a");
88		for(var i = 0 ,len=anchors.length; i<len ; i++){
89			if(!attrPatt.test(anchors[i].getAttribute(attr)) && 
90				anchors[i].href.replace(/\#[a-zA-Z0-9_]+/,"") == location.href.replace(/\#[a-zA-Z0-9_]+/,"")){
91				anchors[i].rel = anchors[i].href;
92				anchors[i].href = "javascript:void(0)";
93				anchors[i].onclick=function(){SmoothScroll(this)}
94			}
95		}
96	});
97
98}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.