1/* 2 * ç§»å¨ç«¯æ¨¡æå¯¼èªå¯ç¹å»èªå¨æ»å¨ 0.1.4 3 * Date: 2017-01-11 4 * by: foshang 5 * 导èªå¯å·¦å³æ»å¨ï¼å¯ç¹å»è¾¹ç¼çä¸ä¸ªï¼èªå¨æ»å¨ä¸ä¸ä¸ªå°å¯è§èå´ãä¾èµäºiscroll.jsã 6 */ 7(function ($) { 8 $.fn.navbarscroll = function (options) { 9 //åç§å±æ§ãåæ° 10 var _defaults = { 11 className:'cur', //å½åéä¸ç¹å»å ç´ çclassç±»å 12 clickScrollTime:300, //ç¹å»åæ»å¨æ¶é´ 13 duibiScreenWidth:0.4, //åä½ä»¥rem为åï¼é»è®¤ä¸º0.4rem 14 scrollerWidth:3, //åä½ä»¥px为åï¼é»è®¤ä¸º3,[ä» ç¨äºç¹æ®æ åµï¼å¤å±å®½åº¦å ä¸ºå°æ°ç¹é æçä¸ç²¾åæ åµ] 15 defaultSelect:0, //åå§éä¸ç¬¬n个ï¼é»è®¤ç¬¬0个 16 fingerClick:0, //ç®æ 第0æ1个é项触å,å¿ é¡»æ¯ä¸é¡¹é¿åº¦ä¸è´ï¼æ¹å¯ç¨æ¤é¡¹ 17 endClickScroll:function(thisObj){}//åè°å½æ° 18 } 19 var _opt = $.extend(_defaults, options); 20 this.each(function () { 21 //æä»¶å®ç°ä»£ç 22 var _wrapper = $(this); 23 var _win = $(window); 24 var _win_width = _win.width(),_wrapper_width = _wrapper.width(),_wrapper_off_left = _wrapper.offset().left; 25 var _wrapper_off_right=_win_width-_wrapper_off_left-_wrapper_width; 26 var _obj_scroller = _wrapper.children('.scroller'); 27 var _obj_ul = _obj_scroller.children('ul'); 28 var _obj_li = _obj_ul.children('li'); 29 var _scroller_w = 0; 30 _obj_li.css({"margin-left":"0","margin-right":"0"}); 31 for (var i = 0; i < _obj_li.length; i++) { 32 _scroller_w += _obj_li[i].offsetWidth; 33 } 34 _obj_scroller.width(_scroller_w+_opt.scrollerWidth); 35 var myScroll = new IScroll('#'+_wrapper.attr('id'), { 36 eventPassthrough: true, 37 scrollX: true, 38 scrollY: false, 39 preventDefault: false 40 }); 41 _init(_obj_li.eq(_opt.defaultSelect)); 42 _obj_li.click(function(){ 43 _init($(this)); 44 }); 45 //è§£å³PCç«¯è°·ææµè§å¨æ¨¡æçææºå±å¹åºç°è«åçå¡é¡¿ç°è±¡ï¼æ»å¨æ¶ç¦æ¢é»è®¤äºä»¶ï¼2017-01-11ï¼ 46 _wrapper[0].addEventListener('touchmove',function (e){e.preventDefault();},false); 47 function _init(thiObj){ 48 var $this_obj=thiObj; 49 var duibi=_opt.duibiScreenWidth*_win_width/10,this_index=$this_obj.index(),this_off_left=$this_obj.offset().left,this_pos_left=$this_obj.position().left,this_width=$this_obj.width(),this_prev_width=$this_obj.prev('li').width(),this_next_width=$this_obj.next('li').width(); 50 var this_off_right=_win_width-this_off_left-this_width; 51 if(_scroller_w+2>_wrapper_width){ 52 if(_opt.fingerClick==1){ 53 if(this_index==1){ 54 myScroll.scrollTo(-this_pos_left+this_prev_width,0, _opt.clickScrollTime); 55 }else if(this_index==0){ 56 myScroll.scrollTo(-this_pos_left,0, _opt.clickScrollTime); 57 }else if(this_index==_obj_li.length-2){ 58 myScroll.scrollBy(this_off_right-_wrapper_off_right-this_width,0, _opt.clickScrollTime); 59 }else if(this_index==_obj_li.length-1){ 60 myScroll.scrollBy(this_off_right-_wrapper_off_right,0, _opt.clickScrollTime); 61 }else{ 62 if(this_off_left-_wrapper_off_left-(this_width*_opt.fingerClick)<duibi){ 63 myScroll.scrollTo(-this_pos_left+this_prev_width+(this_width*_opt.fingerClick),0, _opt.clickScrollTime); 64 }else if(this_off_right-_wrapper_off_right-(this_width*_opt.fingerClick)<duibi){ 65 myScroll.scrollBy(this_off_right-this_next_width-_wrapper_off_right-(this_width*_opt.fingerClick),0, _opt.clickScrollTime); 66 } 67 } 68 }else{ 69 if(this_index==1){ 70 myScroll.scrollTo(-this_pos_left+this_prev_width,0, _opt.clickScrollTime); 71 }else if(this_index==_obj_li.length-1){ 72 if(this_off_right-_wrapper_off_right>1||this_off_right-_wrapper_off_right<-1){ 73 myScroll.scrollBy(this_off_right-_wrapper_off_right,0, _opt.clickScrollTime); 74 } 75 }else{ 76 if(this_off_left-_wrapper_off_left<duibi){ 77 myScroll.scrollTo(-this_pos_left+this_prev_width,0, _opt.clickScrollTime); 78 }else if(this_off_right-_wrapper_off_right<duibi){ 79 myScroll.scrollBy(this_off_right-this_next_width-_wrapper_off_right,0, _opt.clickScrollTime); 80 } 81 } 82 } 83 } 84 $this_obj.addClass(_opt.className).siblings('li').removeClass(_opt.className); 85 _opt.endClickScroll.call(this,$this_obj); 86 } 87 }); 88 }; 89})(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.