欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js實(shí)現(xiàn)移動(dòng)端導(dǎo)航點(diǎn)擊自動(dòng)滑動(dòng)效果

 更新時(shí)間:2017年07月18日 14:10:15   作者:HeavyShell  
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)移動(dòng)端導(dǎo)航點(diǎn)擊自動(dòng)滑動(dòng)效果,導(dǎo)航可左右滑動(dòng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js實(shí)現(xiàn)移動(dòng)端導(dǎo)航點(diǎn)擊滑動(dòng)效果的具體代碼,供大家參考,具體內(nèi)容如下

移動(dòng)端模擬導(dǎo)航可點(diǎn)擊自動(dòng)滑動(dòng) 0.1.4。

導(dǎo)航可左右滑動(dòng),可點(diǎn)擊邊緣的一個(gè),自動(dòng)滾動(dòng)下一個(gè)到可視范圍【依賴(lài)于iscroll.js】。

廢話(huà)不多說(shuō)直接上代碼:

/* 
 * 移動(dòng)端模擬導(dǎo)航可點(diǎn)擊自動(dòng)滑動(dòng) 0.1.4 
 * Date: 2017-01-11 
 * by: xiewei 
 * 導(dǎo)航可左右滑動(dòng),可點(diǎn)擊邊緣的一個(gè),自動(dòng)滾動(dòng)下一個(gè)到可視范圍【依賴(lài)于iscroll.js】 
 */ 
(function ($) { 
 $.fn.navbarscroll = function (options) { 
 //各種屬性、參數(shù) 
 var _defaults = { 
 className:'cur', //當(dāng)前選中點(diǎn)擊元素的class類(lèi)名 
 clickScrollTime:300, //點(diǎn)擊后滑動(dòng)時(shí)間 
 duibiScreenWidth:0.4, //單位以rem為準(zhǔn),默認(rèn)為0.4rem 
 scrollerWidth:3, //單位以px為準(zhǔn),默認(rèn)為3,[僅用于特殊情況:外層寬度因?yàn)樾?shù)點(diǎn)造成的不精準(zhǔn)情況] 
 defaultSelect:0, //初始選中第n個(gè),默認(rèn)第0個(gè) 
 fingerClick:0, //目標(biāo)第0或1個(gè)選項(xiàng)觸發(fā),必須每一項(xiàng)長(zhǎng)度一致,方可用此項(xiàng) 
 endClickScroll:function(thisObj){}//回調(diào)函數(shù) 
 } 
 var _opt = $.extend(_defaults, options); 
 this.each(function () { 
 //插件實(shí)現(xiàn)代碼 
 var _wrapper = $(this); 
 var _win = $(window); 
 var _win_width = _win.width(),_wrapper_width = _wrapper.width(),_wrapper_off_left = _wrapper.offset().left; 
 var _wrapper_off_right=_win_width-_wrapper_off_left-_wrapper_width; 
 var _obj_scroller = _wrapper.children('.scroller'); 
 var _obj_ul = _obj_scroller.children('ul'); 
 var _obj_li = _obj_ul.children('li'); 
 var _scroller_w = 0; 
 _obj_li.css({"margin-left":"0","margin-right":"0"}); 
 for (var i = 0; i < _obj_li.length; i++) { 
 _scroller_w += _obj_li[i].offsetWidth; 
 } 
 _obj_scroller.width(_scroller_w+_opt.scrollerWidth); 
 var myScroll = new IScroll('#'+_wrapper.attr('id'), { 
 eventPassthrough: true, 
 scrollX: true, 
 scrollY: false, 
 preventDefault: false 
 }); 
 _init(_obj_li.eq(_opt.defaultSelect)); 
 _obj_li.click(function(){ 
 _init($(this)); 
 }); 
 //解決PC端谷歌瀏覽器模擬的手機(jī)屏幕出現(xiàn)莫名的卡頓現(xiàn)象,滑動(dòng)時(shí)禁止默認(rèn)事件(2017-01-11) 
 _wrapper[0].addEventListener('touchmove',function (e){e.preventDefault();},false); 
 function _init(thiObj){ 
 var $this_obj=thiObj; 
 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(); 
 var this_off_right=_win_width-this_off_left-this_width; 
 if(_scroller_w+2>_wrapper_width){ 
  if(_opt.fingerClick==1){ 
  if(this_index==1){ 
  myScroll.scrollTo(-this_pos_left+this_prev_width,0, _opt.clickScrollTime); 
  }else if(this_index==0){ 
  myScroll.scrollTo(-this_pos_left,0, _opt.clickScrollTime); 
  }else if(this_index==_obj_li.length-2){ 
  myScroll.scrollBy(this_off_right-_wrapper_off_right-this_width,0, _opt.clickScrollTime); 
  }else if(this_index==_obj_li.length-1){ 
  myScroll.scrollBy(this_off_right-_wrapper_off_right,0, _opt.clickScrollTime); 
  }else{ 
  if(this_off_left-_wrapper_off_left-(this_width*_opt.fingerClick)<duibi){ 
  myScroll.scrollTo(-this_pos_left+this_prev_width+(this_width*_opt.fingerClick),0, _opt.clickScrollTime); 
  }else if(this_off_right-_wrapper_off_right-(this_width*_opt.fingerClick)<duibi){ 
  myScroll.scrollBy(this_off_right-this_next_width-_wrapper_off_right-(this_width*_opt.fingerClick),0, _opt.clickScrollTime); 
  } 
  } 
  }else{ 
  if(this_index==1){ 
  myScroll.scrollTo(-this_pos_left+this_prev_width,0, _opt.clickScrollTime); 
  }else if(this_index==_obj_li.length-1){ 
  if(this_off_right-_wrapper_off_right>1||this_off_right-_wrapper_off_right<-1){ 
  myScroll.scrollBy(this_off_right-_wrapper_off_right,0, _opt.clickScrollTime); 
  } 
  }else{ 
  if(this_off_left-_wrapper_off_left<duibi){ 
  myScroll.scrollTo(-this_pos_left+this_prev_width,0, _opt.clickScrollTime); 
  }else if(this_off_right-_wrapper_off_right<duibi){ 
  myScroll.scrollBy(this_off_right-this_next_width-_wrapper_off_right,0, _opt.clickScrollTime); 
  } 
  } 
  } 
 } 
 $this_obj.addClass(_opt.className).siblings('li').removeClass(_opt.className); 
 _opt.endClickScroll.call(this,$this_obj); 
 } 
 }); 
 }; 
})(jQuery);

截圖:

提供demo地址:

更多關(guān)于滑動(dòng)效果的專(zhuān)題,請(qǐng)點(diǎn)擊下方鏈接查看:

javascript滑動(dòng)操作匯總

jquery滑動(dòng)操作匯總

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論