PageSourceSearch

https://panjin.gov.cn/skin/govpjszf/cms/jquery.cxscroll.js

js panjin.gov.cn collected 2026-09-25 02:39:45 UTC 6,313 bytes, 217 lines download raw bytes

1/*!
2 * jQuery cxScroll 1.2.1
3 * http://code.ciaoca.com/
4 * https://github.com/ciaoca/cxScroll
5 * E-mail: [email protected]
6 * Released under the MIT license
7 * Date: 2014-03-10
8 */
9(function($){
10	$.fn.cxScroll=function(settings){
11		if(!this.length){return};
12		settings=$.extend({},$.cxScroll.defaults,settings);
13
14		var obj=this;
15		var scroller={
16			lock:false,
17			dom:{}
18		};
19
20		scroller.init=function(){
21			scroller.dom.box=obj.find(".box");
22			scroller.dom.list=scroller.dom.box.find(".list");
23			scroller.dom.items=scroller.dom.list.find("li");
24			scroller.itemSum=scroller.dom.items.length;
25
26			// 没有元素或只有1个元素时,不进行滚动
27			if(scroller.itemSum<=1){return};
28
29			scroller.dom.prevBtn=obj.find(".prev");
30			scroller.dom.nextBtn=obj.find(".next");
31			scroller.itemWidth=scroller.dom.items.outerWidth();
32			scroller.itemHeight=scroller.dom.items.outerHeight();
33
34			if(settings.direction=="left"||settings.direction=="right"){
35				// 容器宽度不足时,不进行滚动
36				if(scroller.itemWidth*scroller.itemSum<=scroller.dom.box.outerWidth()){return};
37
38				scroller.prevVal="left";
39				scroller.nextVal="right";
40				scroller.moveVal=scroller.itemWidth;
41			}else{
42				// 容器高度不足时,不进行滚动
43				if(scroller.itemHeight*scroller.itemSum<=scroller.dom.box.outerHeight()){return};
44
45				scroller.prevVal="top";
46				scroller.nextVal="bottom";
47				scroller.moveVal=scroller.itemHeight;
48			};
49
50			// 元素:后补
51			scroller.dom.list.append(scroller.dom.list.html());
52
53			// 添加元素:手动操作按钮
54			if(settings.prevBtn&&!scroller.dom.prevBtn.length){
55				scroller.dom.prevBtn=$("<a></a>",{"class":"prev"}).prependTo(obj);
56			};
57			if(settings.nextBtn&&!scroller.dom.nextBtn.length){
58				scroller.dom.nextBtn=$("<a></a>",{"class":"next"}).prependTo(obj);
59			};
60
61			// 事件:鼠标移入停止,移出开始
62			if(settings.auto){
63				obj.hover(function(){
64					settings.auto=false;
65					scroller.lock=false;
66					scroller.off();
67				},function(){
68					settings.auto=true;
69					scroller.lock=false;
70					scroller.on();
71				});
72			};
73
74			scroller.bindEvents();
75			scroller.on();
76		};
77		
78		scroller.bindEvents=function(){
79			if(settings.nextBtn&&scroller.dom.prevBtn.length){
80				scroller.dom.nextBtn.bind("click",function(){
81					if(!scroller.lock){
82						scroller.goto(scroller.nextVal,settings.accel);
83					};
84				});
85			};
86			if(settings.prevBtn&&scroller.dom.prevBtn.length){
87				scroller.dom.prevBtn.bind("click",function(){
88					if(!scroller.lock){
89						scroller.goto(scroller.prevVal,settings.accel);
90					};
91				});
92			};
93		};
94
95		// 方法:开始
96		scroller.on=function(){
97			if(!settings.auto){return};
98			if(typeof(scroller.run)!=="undefined"){
99				clearTimeout(scroller.run);
100			};
101
102			scroller.run=setTimeout(function(){
103				scroller.goto(settings.direction);
104			},settings.time);
105		};
106
107		// 方法:停止
108		scroller.off=function(){
109			scroller.dom.box.stop(true);
110			if(typeof(scroller.run)!=="undefined"){
111				clearTimeout(scroller.run);
112			};
113		};
114
115		// 方法:滚动
116		scroller.goto=function(d,t){
117			scroller.off();
118			if(settings.controlLock){
119				scroller.lock=true;
120			};
121
122			var _max;	// _max	滚动的最大限度
123			var _dis;	// _dis	滚动的距离
124			var _speed=t||settings.speed;
125
126			switch(d){
127				case "left":
128				case "top":
129					_max=0;
130					if(d=="left"){
131						if(parseInt(scroller.dom.box.scrollLeft(),10)==0){
132							scroller.dom.box.scrollLeft(scroller.itemSum*scroller.moveVal);
133						};
134						_dis=scroller.dom.box.scrollLeft()-(scroller.moveVal*settings.step);
135						if(_dis%scroller.itemWidth>0){
136							_dis-=(_dis%scroller.itemWidth)-scroller.itemWidth;
137						};
138						if(_dis<_max){_dis=_max};
139						scroller.dom.box.animate({"scrollLeft":_dis},_speed,settings.easing,function(){
140							if(parseInt(scroller.dom.box.scrollLeft(),10)<=_max){
141								scroller.dom.box.scrollLeft(0);
142							};
143						});
144					}else{
145						if(parseInt(scroller.dom.box.scrollTop(),10)==0){
146							scroller.dom.box.scrollTop(scroller.itemSum*scroller.moveVal);
147						};
148						_dis=scroller.dom.box.scrollTop()-(scroller.moveVal*settings.step);
149						if(_dis%scroller.itemHeight>0){
150							_dis-=(_dis%scroller.itemHeight)-scroller.itemHeight;
151						};
152						if(_dis<_max){_dis=_max};
153						scroller.dom.box.animate({"scrollTop":_dis},_speed,settings.easing,function(){
154							if(parseInt(scroller.dom.box.scrollTop(),10)<=_max){
155								scroller.dom.box.scrollTop(0);
156							};
157						});
158					};
159					break;
160	
161				case "right":
162				case "bottom":
163					_max=scroller.itemSum*scroller.moveVal;
164					if(d=="right"){
165						_dis=scroller.dom.box.scrollLeft()+(scroller.moveVal*settings.step);
166						if(_dis%scroller.itemWidth>0){
167							_dis-=(_dis%scroller.itemWidth);
168						};
169						if(_dis>_max){_dis=_max};
170						scroller.dom.box.animate({"scrollLeft":_dis},_speed,settings.easing,function(){
171							if(parseInt(scroller.dom.box.scrollLeft(),10)>=_max){
172								scroller.dom.box.scrollLeft(0);
173							};
174						});
175					}else{
176						_dis=scroller.dom.box.scrollTop()+(scroller.moveVal*settings.step);
177						if(_dis%scroller.itemHeight>0){
178							_dis-=(_dis%scroller.itemHeight);
179						};
180						if(_dis>_max){_dis=_max};
181						scroller.dom.box.animate({"scrollTop":_dis},_speed,settings.easing,function(){
182							if(parseInt(scroller.dom.box.scrollTop(),10)>=_max){
183								scroller.dom.box.scrollTop(0);
184							};
185						});
186					};
187					break;
188				
189				// not default
190			};
191			
192			scroller.dom.box.queue(function(){
193				if(settings.controlLock){
194					scroller.lock=false;
195				};
196				scroller.on();
197				$(this).dequeue();
198			});
199		};
200
201		scroller.init();
202	};
203
204	// 默认值
205	$.cxScroll={defaults:{
206		direction:"right",	// 滚动方向
207		easing:"swing",		// 缓动方式
208		step:1,				// 滚动步长
209		accel:160,			// 手动滚动速度
210		speed:800,			// 自动滚动速度
211		time:4000,			// 自动滚动间隔时间
212		auto:true,			// 是否自动滚动
213		prevBtn:true,		// 是否使用 prev 按钮
214		nextBtn:true,		// 是否使用 next 按钮
215		safeLock:true		// 滚动时是否锁定控制按钮
216	}};
217})(jQuery);

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.