PageSourceSearch

https://www.imu.edu.cn/index/js/jquery.mScroll.js

js imu.edu.cn collected 2026-10-02 04:54:59 UTC 18,231 bytes, 622 lines download raw bytes

1/*
2======示例=====
3<style>
4body{margin:20px;}
5#focus{height:200px;width:500px;position:relative;margin:auto;border:5px solid #ccc;}
6.frame{width:100%;height:100%;overflow:hidden;}
7.frame .child{height:100%;float:left;}
8.nav{position:absolute;width:60px;height:20px;overflow:hidden;left:50%;bottom:5px;margin-left:-31px;border:1px solid #aaa;}
9.nav a{float:left;width:20px;height:20px;line-height:20px;font-size:12px;color:#000;text-align:center;background:#f5f5f5;}
10.nav a.now{background:#aaa;color:#fff;}
11.prev{right:30px;bottom:5px;width:20px;height:20px;line-height:20px;text-align:center;background:#f5f5f5;position:absolute;color:#000;font-size:12px;font-family:Arial;}
12.next{right:5px;bottom:5px;width:20px;height:20px;line-height:20px;text-align:center;background:#f5f5f5;position:absolute;color:#000;font-size:12px;font-family:Arial;}
13.title{height:30px;line-height:30px;float:left;}
14.count{height:30px;line-height:30px;float:right;}
15.count b{font-weight:normal;}
16.count em{font-style:normal;}
17</style>
18<div class="focus"><a href="javascript:;" class="prev">&lt;</a><a href="javascript:;" class="next">&gt;</a>
19  <div class="frame">
20	<div class="child" style="background:#faa;" title="c1"></div>
21	<div class="child" style="background:#afa;" title="c2"></div>
22	<div class="child" style="background:#aaf;" title="c3"></div>
23	<div class="child" style="background:#ffa;" title="c4"></div>
24	<div class="child" style="background:#aff;" title="c5"></div>
25  </div>
26  <div class="nav">
27	<i>1</i>
28	<i>2</i>
29	<i>3</i>
30	<i>4</i>
31	<i>5</i>
32  </div>
33  <div class="title"></div>
34  <div class="count"><b></b>/<em></em></div>
35</div>
36<script>
37$('.focus .frame').mScroll({
38		     auto : 1,                   //自动开始
39		direction : "h",                 //滚动方向,h横向,v纵向
40		    dtype : "left",              //正反方向
41		  isfocus : 0,                   //是否作为焦点图
42			minsize :	[
43		  						{
44										width:0,
45										size:1
46									},
47									{
48										width:1000,
49										size:4
50									}
51								],                 //最小数量
52		    speed : 500,                 //滚动速度
53		   easing : "",                  //缓冲类型
54				delay : 5000,                //自动滚动间隔
55				  nav : ".focus .nav i",     //导航按钮
56				event : "click",             //导航按钮事件类型
57		scrollnav : 0,                   //导航滚动
58nav_direction : "h",                 //导航方向,h横向,v纵向
59				 prev : ".focus .prev",      //前一个
60				 next : ".focus .next",      //后一个
61				index : ".focus .index",     //当前序号
62				count : ".focus .count b",   //总数
63				title : ".focus .count em",  //标题
64				arrow : 1,                   //是否反转
65				cycle : 1,                   //是否循环
66		mousestop : 1,                   //鼠标划入停止
67	 mousewheel : 0,                   //开启滚轮事件
68				touch : 0,                   //开启触摸事件
69		 callback : function(idx){}      //回调函数
70});
71</script>
72===============
73*/
74//变量解释
75/*
76f=对象主体frame
77s=frame内滚动元素
78c=s内子元素
79n=导航子元素
80np=导航父元素
81ns=导航内滚动元素
82w,h=滚动距离
83ww,hh=原始总长度
84size=s内子元素原始数量
85iv,ti=定时器
86sw=控制开关
87idx=当前序号
88cm=s内子元素边距
89*/
90(function($) {
91	$.fn.mScroll = function(options) {
92		var opts = $.extend({},$.fn.mScroll.defaults,options);
93		this.each(function(){
94			//初始化变量
95			var f = $(this);
96			var s,c,n,np,ns,w,ww,h,hh,wn,hn,size,iv,ti,sw=1,sw1=0,idx=0,ids=0,idx1=0,cm=0;
97			//var tt=5000;
98			
99			//控制判断初始化
100			if(opts.cycle==0){opts.auto=0;}
101			if(opts.touch==1){
102				opts.minsize=1;
103				opts.mousestop=0;
104				opts.mousewheel=0;
105			}
106			
107			function getMinsize(){				
108				if(typeof(opts.minsize)=="object"){
109					var minsize=0;//var minsize=opts.minsize[0].size;
110					for(var i=0;i<opts.minsize.length;i++){
111						var mz=new Object(opts.minsize[i]);
112						if($(window).width()>mz.width){
113							minsize=mz.size;
114						}
115					}
116					return minsize;
117				}
118				else{
119					return opts.minsize;
120				}
121			}
122			
123			if(f.children().size==1){return false;}
124			
125			//生成scroll结构,赋值s
126			if(f.children().is("ul") && f.children().length>1 && !f.children().hasClass("child")){
127				f.children().addClass("scroll");
128			}
129			else{
130				f.children().wrapAll("<div class='scroll' style='height:100%;'></div>");
131			}
132			s = f.find(".scroll");
133			
134			//初始化size
135			size=s.children().length;			
136			
137			
138			//创建c镜像,赋值c
139			if(opts.cycle==1 && size>getMinsize()){s.append(s.html());}
140			c = s.children();
141			
142			//初始化导航
143			n = $(opts.nav);
144			if(opts.scrollnav){
145				wn = parseInt(n.outerWidth()+parseInt(n.css("margin-left"))+parseInt(n.css("margin-right")));
146				hn = parseInt(n.outerHeight()+parseInt(n.css("margin-top"))+parseInt(n.css("margin-bottom")));
147				np= $(opts.nav).parent();
148				n.wrapAll("<div class='scroll' style='height:100%;'></div>");
149				n.width(wn);
150				ns=np.find(".scroll");
151				if(opts.nav_direction=="h"){
152					ns.width(n.length*wn);
153					np.stop().animate({scrollLeft:0},100);
154				}
155				if(opts.nav_direction=="v"){
156					ns.height(n.length*hn);
157					np.stop().animate({scrollTop:0},100);
158				}
159			}
160			n.eq(0).addClass("now");
161			if(opts.cycle!==1){$(opts.prev).css("opacity","0.3");}
162			
163			//初始化各元素尺寸
164			function setWH(){
165				if(opts.direction=="h"){
166					setH();
167					s.width(100000);
168					s.height("100%");
169					f.stop().animate({scrollLeft:0},100);
170				}
171				if(opts.direction=="v"){		
172					setV();		
173					s.height(100000);				
174					f.stop().animate({scrollTop:0},100);
175				}
176			}
177			setWH();
178			
179			//尺寸设置函数
180			function setH(){
181				f.css("width","");
182				c.css("width","");
183				cm=parseInt(c.last().css("margin-left"))+parseInt(c.last().css("margin-right"));
184				if(cm==0){
185					w = Math.floor(f.width()/getMinsize());
186					if(opts.isfocus!=1){
187						f.width(w*getMinsize());
188					}
189					else{
190						f.width("auto");
191					}
192					c.width(w);
193				}
194				else{
195					//if(opts.isfocus!=1){
196						w=Math.floor((f.width()+cm)/4);
197						c.width(w-cm);
198						f.width(w*getMinsize()-cm);
199					//}
200				}
201				ww=c.length*w;
202			}
203			function setV(){
204				f.height("auto");
205				c.css("height","");
206				cm=parseInt(c.css("margin-top"))+parseInt(c.css("margin-bottom"));
207				if(cm==0){
208					h = Math.floor(f.height()/getMinsize());
209					if(opts.isfocus!=1){
210						f.height(h*getMinsize());
211					}
212					else{
213						f.height("auto");
214					}
215					c.height(h);
216				}
217				else{
218					if(opts.isfocus!=1){
219						h=c.height()+cm;
220						f.height(h*getMinsize()-cm);
221					}
222				}
223				hh=c.length*h;
224			}
225			
226			//设置title
227			$(opts.count).text(size);
228			$(opts.title).text(c.eq(0).attr("title"));
229			$(opts.index).text(1);
230			
231			//焦点图自适应
232			$(window).resize(function(){
233				if(f.is(":visible")){rs();}
234			});
235			rs();
236			
237			//自适应
238			function rs(){
239				sw==0;
240				clearTimeout(ti);
241				if(getMinsize()!=0){
242					if(opts.direction=="h"){
243						setH();
244						f.stop().scrollLeft(idx*w);
245					}
246					if(opts.direction=="v"){
247						setV();
248						f.stop().scrollTop(idx*h);
249					}
250					ti=setTimeout(function(){
251						sw=1;
252					},500);
253					//恢复轮播
254					if(opts.direction=="h"){
255						if(s.width()!==100000){
256							setWH();
257						}
258					}
259					if(opts.direction=="v"){
260						if(s.height()!==100000){
261							setWH();
262						}
263					}
264					if(size<=getMinsize()){
265						s.css({margin:"auto",width:w*size});
266						$(opts.prev).hide();
267						$(opts.next).hide();
268					}
269					else{
270						if(opts.direction=="h"){
271							s.removeAttr("style").width(100000);
272						}
273						if(opts.direction=="v"){
274							s.removeAttr("style").height(100000);
275						}
276						$(opts.prev).show();
277						$(opts.next).show();
278					}
279				}
280				else{
281					//解除轮播
282					f.removeAttr("style");
283					s.removeAttr("style");					
284				}
285				
286			}
287			
288			//判断c数量是否满足开始条件
289			if(size>getMinsize()){
290			
291			//自动开始
292			if(opts.auto==1){
293				run();
294			}
295			
296			function run(){				
297				var t=opts.delay;
298				if(idx==0){
299					//t=tt;
300				}				
301				clearTimeout(iv);
302				iv=setTimeout(function(){
303					move(opts.dtype);
304					run();
305				},t);
306			}
307			
308			//执行回调函数
309			if(typeof(opts.callback)=="function"){
310				opts.callback(idx);
311			}
312			
313			//-------------start-------------//
314			//滚动函数
315			function move(act,speed){
316				if(!speed){speed=opts.speed;}
317				if(sw==1){
318					sw=0;
319					if(act=="left"){
320						if(opts.cycle!=1){
321							if(idx+getMinsize()<size){
322								idx++;ids++;
323								if(opts.direction=="h"){
324									f.animate({scrollLeft:ids*w},speed,opts.easing,function(){sw=1;});
325								}
326								if(opts.direction=="v"){
327									f.animate({scrollTop:ids*h},speed,opts.easing,function(){sw=1;});
328								}
329								$(opts.prev).css("opacity","1");
330								if(idx+getMinsize()==size){
331									$(opts.next).css("opacity","0.3");
332								}
333							}
334							else{
335								sw=1;								
336							}							
337						}
338						if(opts.cycle==1){	
339							if(idx==size-1){idx=0;}
340							else{idx++;}
341							ids++;
342							if(opts.direction=="h"){
343								f.animate({scrollLeft:ids*w},speed,opts.easing,function(){									
344									if(f.scrollLeft()>=ww*0.5){f.scrollLeft(0);ids=0;}
345									sw=1;
346								});
347							}
348							if(opts.direction=="v"){
349								f.animate({scrollTop:ids*h},speed,opts.easing,function(){
350									if(f.scrollTop()>=hh*0.5){f.scrollTop(0);ids=0;}
351									sw=1;
352								});
353							}
354							
355						}
356					}
357					if(act=="right"){
358						if(opts.cycle!=1){
359							if(idx>0){
360								idx--;ids--;
361								if(opts.direction=="h"){
362									f.animate({scrollLeft:ids*w},speed,opts.easing,function(){sw=1;});
363								}
364								if(opts.direction=="v"){
365									f.animate({scrollTop:ids*h},speed,opts.easing,function(){sw=1;});
366								}
367								$(opts.next).css("opacity","1");
368								if(idx==0){
369									$(opts.prev).css("opacity","0.3");									
370								}
371							}
372							else{
373								sw=1;
374							}
375						}
376						if(opts.cycle==1){
377							if(idx==0){idx=size-1;ids=size;}
378							else{idx--;}
379							ids--;
380							if(opts.direction=="h"){
381								if(f.scrollLeft()<=0){f.scrollLeft(ww*0.5);}
382								f.animate({scrollLeft:ids*w},speed,opts.easing,function(){sw=1;});
383							}
384							if(opts.direction=="v"){
385								if(f.scrollTop()<=0){f.scrollTop(hh*0.5);}
386								f.animate({scrollTop:ids*h},speed,opts.easing,function(){sw=1;});
387							}
388						}
389					}						
390					n.removeClass("now");
391					n.eq(idx).addClass("now");
392					$(opts.title).text(c.eq(idx).attr("title"));
393					$(opts.index).text(idx+1);					
394					if(opts.scrollnav){autonav();}
395					if(typeof(opts.callback)=="function"){
396						opts.callback(idx);//执行自定义动画
397					}
398				}
399			}
400			//左右按钮
401			if(opts.prev){
402				$(opts.prev).hover(function(){sw=1;});
403				$(opts.prev).unbind("click");
404				$(opts.prev).click(function(){
405					if(opts.arrow==1){move("right");}
406					else{move("left");}
407					if(opts.auto){
408						//clearInterval(iv);
409						//iv = window.setInterval(function(){move(opts.dtype);},opts.delay);
410						run();
411					}
412					if(idx1>0){idx1--;c.eq(idx1).click();}
413					
414				});
415				
416			}
417			if(opts.next){
418				$(opts.next).hover(function(){sw=1;});
419				$(opts.next).unbind("click");
420				$(opts.next).click(function(){
421					if(opts.arrow==1){move("left");}
422					else{move("right");}
423					if(opts.auto){
424						//clearInterval(iv);
425						//iv = window.setInterval(function(){move(opts.dtype);},opts.delay);
426						run();
427					}
428					if(idx1<size-1){idx1++;c.eq(idx1).click();}
429					
430				});
431			}
432			c.click(function(){
433				idx1=$(this).index();
434			});
435			
436			//导航溢出部分滑动显示
437			function autonav(){
438				if(opts.nav_direction=="h"){					
439					if(np.width()==wn){					
440						np.stop().animate({scrollLeft:wn*idx},opts.navspeed);
441					}
442					else{
443						if(idx*wn==np.scrollLeft()){
444							np.stop().animate({scrollLeft:np.scrollLeft()-wn},opts.navspeed);
445						}
446						if((idx+1)*wn==np.scrollLeft()+np.width()){
447							np.stop().animate({scrollLeft:np.scrollLeft()+wn},opts.navspeed);
448						}
449						if(idx==0){np.stop().animate({scrollLeft:0},opts.navspeed);}
450						if(idx==size-1){np.stop().animate({scrollLeft:size*wn},opts.navspeed);}
451						if(np.width()%wn!=0){console.log('宽度设置错误');}
452					}
453				}
454				if(opts.nav_direction=="v"){
455					if(idx*hn==np.scrollTop()){
456						np.stop().animate({scrollTop:np.scrollTop()-hn},opts.navspeed);
457					}
458					if((idx+1)*hn==np.scrollTop()+np.height()){
459						np.stop().animate({scrollTop:np.scrollTop()+hn},opts.navspeed);
460					}
461					if(idx==0){np.stop().animate({scrollTop:0},opts.navspeed);}
462					if(idx==size-1){np.stop().animate({scrollTop:size*hn},opts.navspeed);}
463				}
464			}
465			//导航点击
466			n.each(function(index, element) {
467				$(this).bind(opts.event,function(){
468					if(opts.direction=="h"){f.stop().animate({scrollLeft:index*w},opts.speed,opts.easing,function(){sw=1;});}
469					if(opts.direction=="v"){f.stop().animate({scrollTop:index*h},opts.speed,opts.easing,function(){sw=1;});}
470					idx=index;
471					ids=index;
472					$(opts.prev).css("opacity","1");
473					$(opts.next).css("opacity","1");
474					if(idx+getMinsize()==size){
475							$(opts.next).css("opacity","0.3");
476					}
477					if(idx==0){
478							$(opts.prev).css("opacity","0.3");
479					}
480					n.removeClass("now");
481					n.eq(idx).addClass("now");
482					if(opts.scrollnav){autonav();}
483					$(opts.title).text(c.eq(idx).attr("alt"));
484					//执行回调函数
485					if(typeof(opts.callback)=="function"){
486						opts.callback(idx);
487					}
488					if(opts.auto){
489						//clearInterval(iv);
490						//iv = window.setInterval(function(){move(opts.dtype);},opts.delay);
491						run();
492					}						
493				});
494			});
495			//鼠标滚轮
496			if(opts.mousewheel){
497				f.mousewheel(function(event,delta,deltaX,deltaY){
498					if(delta<0){
499						if(opts.arrow==1){move("left");}
500						else{move("right");}
501					}
502					else{
503						if(opts.arrow==1){move("right");}
504						else{move("left");}
505					}
506					event.stopPropagation();
507					event.preventDefault();
508				});
509			}
510			//鼠标划入停止
511			if(opts.mousestop && !opts.mousewheel){
512				f.hover(function(){sw=0},function(){sw=1});
513			}
514			
515			//触摸控制
516			if(opts.touch && document.addEventListener){
517				f.attr("id","frame"+f.offset().top);
518				var touch,p0,fl,m;
519				var obj1=document.getElementById(f.attr("id"));
520				var start,end="";
521				
522				obj1.addEventListener('touchstart',function(event){
523					if(sw==1){
524						sw1=1;
525						touch = event.targetTouches[0];
526						if(opts.direction=="h"){
527							p0=touch.screenX;
528							start=touch.screenX;
529							fl=f.scrollLeft();
530							m=w;
531						}
532						if(opts.direction=="v"){
533							p0=touch.screenY;
534							start=touch.screenY;
535							fl=f.scrollTop();
536							m=h;
537						}						
538						if(opts.auto){
539							clearInterval(iv);
540						}
541					}
542				},false);
543				obj1.addEventListener('touchmove',function(event){
544					if(sw==1 && sw1==1){
545						touch = event.targetTouches[0];
546						if(opts.direction=="h"){
547							f.scrollLeft(fl-(touch.screenX-p0));
548							end=touch.screenX;
549							if(Math.abs(touch.screenX-p0)>$(window).width()*0.05){
550								event.preventDefault();//阻止浏览器默认事件
551							}
552						}
553						if(opts.direction=="v"){
554							f.scrollTop(fl-(touch.screenY-p0));
555							end=touch.screenY;
556							if(Math.abs(touch.screenY-p0)>f.height()*0.05){
557								
558							}
559							event.preventDefault();//阻止浏览器默认事件
560						}
561					}
562				},false);
563				obj1.addEventListener('touchend',function(event){
564					if(sw==1 && end!=""){
565						if(end-start<m*-0.1){
566							move("left",(m-Math.abs(end-start))/m*opts.speed);
567						}
568						else if(end-start>m*0.1){
569							move("right",(m-Math.abs(end-start))/m*opts.speed);
570						}
571						else{
572							sw=0;						
573							if(opts.direction=="h"){
574								f.stop().animate({scrollLeft:ids*m},opts.speed*0.5,opts.easing,function(){sw=1;});
575							}
576							else{
577								f.stop().animate({scrollTop:ids*m},opts.speed*0.5,opts.easing,function(){sw=1;});
578							}
579							
580						}
581						if(opts.auto){
582							//clearInterval(iv);
583							//iv = window.setInterval(function(){move(opts.dtype);},opts.delay);
584							run();
585						}
586						sw1=0;
587						end="";
588					}
589				},false);
590			}
591				
592			//-------------end-------------//
593			}
594		})
595	};
596	$.fn.mScroll.defaults = {
597		     auto : 1,                    //自动开始
598		direction : "h",                  //滚动方向,h横向,v纵向
599		    dtype : "left",               //正反方向
600		  isfocus : 0,                    //是否作为焦点图
601		  minsize : 1,                    //最小数量
602		    speed : 500,                  //滚动速度
603		   easing : "",                   //缓冲类型
604			delay : 5000,                 //自动滚动间隔
605			  nav : null,                 //导航按钮
606			event : "click",              //导航事件
607        scrollnav : 0,                    //导航滚动
608		 navspeed : 500,                  //导航滚动速度
609    nav_direction : "h",                  //导航方向,h横向,v纵向
610			 prev : null,                 //前一个
611			 next : null,                 //后一个
612		    index : null,                 //当前序号
613			count : null,                 //总数
614			title : null,                 //标题
615			arrow : 1,                    //是否反转
616			cycle : 1,                    //是否循环
617		mousestop : 1,                    //鼠标划入停止
618	   mousewheel : 0,                    //开启滚轮事件
619	        touch : 0,                    //开启触摸事件
620		 callback : function(idx){}       //回掉函数
621	}
622})(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.