PageSourceSearch

https://www.tongjihospital.com.cn/static/index/js/Marquee.js

js tongjihospital.com.cn collected 2026-10-02 18:35:22 UTC 9,235 bytes, 314 lines download raw bytes

1/**
2 * @classDescription 超级Marquee,可做图片导航,图片轮换
3 * @author Aken Li(www.kxbd.com)
4 * @date 2009-07-27
5 * @dependence jQuery 1.3.2
6 * @DOM
7 *  	<div id="marquee">
8 *  		<ul>
9 *   			<li></li>
10 *   			<li></li>
11 *  		</ul>
12 *  	</div>
13 * @CSS
14 *  	#marquee {width:200px;height:50px;overflow:hidden;}
15 * @Usage
16 *  	$('#marquee').kxbdSuperMarquee(options);
17 * @options
18 *		distance:200,//一次滚动的距离
19 *		duration:20,//缓动效果,单次移动时间,越小速度越快,为0时无缓动效果
20 *		time:5,//停顿时间,单位为秒
21 *		direction: 'left',//滚动方向,'left','right','up','down'
22 *		scrollAmount:1,//步长
23 *		scrollDelay:20//时长,单位为毫秒
24 *		isEqual:true,//所有滚动的元素长宽是否相等,true,false
25 *		loop: 0,//循环滚动次数,0时无限
26 *		btnGo:{left:'#goL',right:'#goR'},//控制方向的按钮ID,有四个属性left,right,up,down分别对应四个方向
27 *		eventGo:'click',//鼠标事件
28 *		controlBtn:{left:'#goL',right:'#goR'},//控制加速滚动的按钮ID,有四个属性left,right,up,down分别对应四个方向
29 *		newAmount:4,//加速滚动的步长
30 *		eventA:'mouseenter',//鼠标事件,加速
31 *		eventB:'mouseleave',//鼠标事件,原速
32 *		navId:'#marqueeNav', //导航容器ID,导航DOM:<ul><li>1</li><li>2</li><ul>,导航CSS:.navOn
33 *		eventNav:'click' //导航事件
34 */
35(function($){
36
37	$.fn.kxbdSuperMarquee = function(options){
38		var opts = $.extend({},$.fn.kxbdSuperMarquee.defaults, options);
39		
40		return this.each(function(){
41			var $marquee = $(this);//滚动元素容器
42			var _scrollObj = $marquee.get(0);//滚动元素容器DOM
43			var scrollW = $marquee.width();//滚动元素容器的宽度
44			var scrollH = $marquee.height();//滚动元素容器的高度
45			var $element = $marquee.children(); //滚动元素
46			var $kids = $element.children();//滚动子元素
47			var scrollSize=0;//滚动元素尺寸
48			var _type = (opts.direction == 'left' || opts.direction == 'right') ? 1:0;//滚动类型,1左右,0上下
49			var scrollId, rollId, isMove, marqueeId;
50			var t,b,c,d,e; //滚动动画的参数,t:当前时间,b:开始的位置,c:改变的位置,d:持续的时间,e:结束的位置
51			var _size, _len; //子元素的尺寸与个数
52			var $nav,$navBtns;
53			var arrPos = []; 
54			var numView = 0; //当前所看子元素
55			var numRoll=0; //轮换的次数
56			var numMoved = 0;//已经移动的距离
57
58			//防止滚动子元素比滚动元素宽而取不到实际滚动子元素宽度
59			$element.css(_type?'width':'height',10000);
60			//获取滚动元素的尺寸
61			var navHtml = '<ul>';
62			if (opts.isEqual) {
63				_size = $kids[_type?'outerWidth':'outerHeight']();
64				_len = $kids.length;
65				scrollSize = _size * _len;
66				for(var i=0;i<_len;i++){
67					arrPos.push(i*_size);
68					navHtml += '<li></li>';
69				}
70			}else{
71				$kids.each(function(i){
72					arrPos.push(scrollSize);
73					scrollSize += $(this)[_type?'outerWidth':'outerHeight']();
74					navHtml += '<li></li>';
75				});
76			}
77			navHtml += '</ul>';
78			
79			//滚动元素总尺寸小于容器尺寸,不滚动
80			if (scrollSize<(_type?scrollW:scrollH)) return; 
81			//克隆滚动子元素将其插入到滚动元素后,并设定滚动元素宽度
82			$element.append($kids.clone()).css(_type?'width':'height',scrollSize*2);
83			
84			//轮换导航
85			if (opts.navId) {
86				$nav = $(opts.navId).append(navHtml).hover( stop, start );
87				$navBtns = $('li', $nav);
88				$navBtns.each(function(i){
89					$(this).bind(opts.eventNav,function(){
90						if(isMove) return;
91						if(numView==i) return;
92						rollFunc(arrPos[i]);
93						$navBtns.eq(numView).removeClass('navOn');
94						numView = i;
95						$(this).addClass('navOn');
96					});
97				});
98				$navBtns.eq(numView).addClass('navOn');
99			}
100			
101			//设定初始位置
102			if (opts.direction == 'right' || opts.direction == 'down') {
103				_scrollObj[_type?'scrollLeft':'scrollTop'] = scrollSize;
104			}else{
105				_scrollObj[_type?'scrollLeft':'scrollTop'] = 0;
106			}
107			
108			if(opts.isMarquee){
109				//滚动开始
110				//marqueeId = setInterval(scrollFunc, opts.scrollDelay);
111				marqueeId = setTimeout(scrollFunc, opts.scrollDelay);
112				//鼠标划过停止滚动
113				$marquee.hover(
114					function(){
115						clearInterval(marqueeId);
116					},
117					function(){
118						//marqueeId = setInterval(scrollFunc, opts.scrollDelay);
119						clearInterval(marqueeId);
120						marqueeId = setTimeout(scrollFunc, opts.scrollDelay);
121					}
122				);
123				
124				//控制加速运动
125				if(opts.controlBtn){
126					$.each(opts.controlBtn, function(i,val){
127						$(val).bind(opts.eventA,function(){
128							opts.direction = i;
129							opts.oldAmount = opts.scrollAmount;
130							opts.scrollAmount = opts.newAmount;
131						}).bind(opts.eventB,function(){
132							opts.scrollAmount = opts.oldAmount;
133						});
134					});
135				}
136			}else{
137				if(opts.isAuto){
138					//轮换开始
139					start();
140					
141					//鼠标划过停止轮换
142					$marquee.hover( stop, start );
143				}
144			
145				//控制前后走
146				if(opts.btnGo){
147					$.each(opts.btnGo, function(i,val){
148						$(val).bind(opts.eventGo,function(){
149							if(isMove == true) return;
150							opts.direction = i;
151							rollFunc();
152							if (opts.isAuto) {
153								stop();
154								start();
155							}
156						});
157					});
158				}
159			}
160			
161			function scrollFunc(){
162				var _dir = (opts.direction == 'left' || opts.direction == 'right') ? 'scrollLeft':'scrollTop';
163				
164				if(opts.isMarquee){
165					if (opts.loop > 0) {
166						numMoved+=opts.scrollAmount;
167						if(numMoved>scrollSize*opts.loop){
168							_scrollObj[_dir] = 0;
169							return clearInterval(marqueeId);
170						} 
171					}
172					var newPos = _scrollObj[_dir]+(opts.direction == 'left' || opts.direction == 'up'?1:-1)*opts.scrollAmount;
173				}else{
174					if(opts.duration){
175						if(t++<d){
176							isMove = true;
177							var newPos = Math.ceil(easeOutQuad(t,b,c,d));
178							if(t==d){
179								newPos = e;
180							}
181						}else{
182							newPos = e;
183							clearInterval(scrollId);
184							isMove = false;
185							return;
186						}
187					}else{
188						var newPos = e;
189						clearInterval(scrollId);
190					}
191				}
192				
193				if(opts.direction == 'left' || opts.direction == 'up'){
194					if(newPos>=scrollSize){
195						newPos-=scrollSize;
196					}
197				}else{
198					if(newPos<=0){
199						newPos+=scrollSize;
200					}
201				}
202				_scrollObj[_dir] = newPos;
203				
204				if(opts.isMarquee){
205					marqueeId = setTimeout(scrollFunc, opts.scrollDelay);
206				}else if(t<d){
207					if(scrollId) clearTimeout(scrollId);
208					scrollId = setTimeout(scrollFunc, opts.scrollDelay);
209				}else{
210					isMove = false;
211				}
212				
213			};
214			
215			function rollFunc(pPos){
216				isMove = true;
217				var _dir = (opts.direction == 'left' || opts.direction == 'right') ? 'scrollLeft':'scrollTop';
218				var _neg = opts.direction == 'left' || opts.direction == 'up'?1:-1;
219
220				numRoll = numRoll +_neg;
221				//得到当前所看元素序号并改变导航CSS
222				if(pPos == undefined&&opts.navId){
223					$navBtns.eq(numView).removeClass('navOn');
224					numView +=_neg;
225					if(numView>=_len){
226						numView = 0;
227					}else if(numView<0){
228						numView = _len-1;
229					}
230					$navBtns.eq(numView).addClass('navOn');
231					numRoll = numView;
232				}
233
234				var _temp = numRoll<0?scrollSize:0;
235				t=0;
236				b=_scrollObj[_dir];
237				//c=(pPos != undefined)?pPos:_neg*opts.distance;
238				e=(pPos != undefined)?pPos:_temp+(opts.distance*numRoll)%scrollSize;
239				if(_neg==1){
240					if(e>b){
241						c = e-b;
242					}else{
243						c = e+scrollSize -b;
244					}
245				}else{
246					if(e>b){
247						c =e-scrollSize-b;
248					}else{
249						c = e-b;
250					}
251				}
252				d=opts.duration;
253				
254				//scrollId = setInterval(scrollFunc, opts.scrollDelay);
255				if(scrollId) clearTimeout(scrollId);
256				scrollId = setTimeout(scrollFunc, opts.scrollDelay);
257			}
258			
259			function start(){
260				rollId = setInterval(function(){
261					rollFunc();
262				}, opts.time*1000);
263			}
264			function stop(){
265				clearInterval(rollId);
266			}
267			
268			function easeOutQuad(t,b,c,d){
269				return -c *(t/=d)*(t-2) + b;
270			}
271			
272			function easeOutQuint(t,b,c,d){
273				return c*((t=t/d-1)*t*t*t*t + 1) + b;
274			}
275
276		});
277	};
278	$.fn.kxbdSuperMarquee.defaults = {
279		isMarquee:false,//是否为Marquee
280		isEqual:true,//所有滚动的元素长宽是否相等,true,false
281		loop: 0,//循环滚动次数,0时无限
282		newAmount:3,//加速滚动的步长
283		eventA:'mousedown',//鼠标事件,加速
284		eventB:'mouseup',//鼠标事件,原速
285		isAuto:true,//是否自动轮换
286		time:5,//停顿时间,单位为秒
287		duration:50,//缓动效果,单次移动时间,越小速度越快,为0时无缓动效果
288		eventGo:'click', //鼠标事件,向前向后走
289		direction: 'left',//滚动方向,'left','right','up','down'
290		scrollAmount:1,//步长
291		scrollDelay:10,//时长
292		eventNav:'click'//导航事件
293	};
294	
295	$.fn.kxbdSuperMarquee.setDefaults = function(settings) {
296		$.extend( $.fn.kxbdSuperMarquee.defaults, settings );
297	};
298	
299})(jQuery);
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314

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.