// javascript document //jquery script $(function(){ //鍒楄〃鑷€傚簲 var ptlistwrp = $('.jq_ptlst'); //鍒楄〃瀹瑰櫒 var vallstliwth = $('.jq_ptlst li').width(); //鍥剧墖瀹藉害锛堝浘鐗囧彲鑳藉寘鎷竟妗嗘牱寮忕瓑锛屽彇li瀹藉害鍙備笌鍙鍥剧墖璁$畻閬垮厤璇樊锛? var valimglth = 1; //鍙鍥炬暟鍙橀噺* var valplstmg = 0; //杈硅窛鍙橀噺* var plstlesmg = 5; //涓寸晫闂磋窛 //鍒楄〃婊氬姩 var plstrolt = $('.jq_plstrolt'); //宸︽粴鍔ㄥ厓绱? var plstrort = $('.jq_plstrort'); //鍙虫粴鍔ㄥ厓绱? var plstimglth = ptlistwrp.find('img').length; //鑾峰彇鍥剧墖鎬绘暟 //瀹藉害鑷€傚簲鏂规硶 function fnautowth(){ //閲嶇疆婊氬姩 $('.jq_ptlst ul').css({'marginleft':'0'}); plstrolt.hide(); plstrort.show(); var plstwrpwth = ptlistwrp.width(); //鑾峰彇褰撳墠鍙鍖哄煙瀹藉害 valimglth = math.floor(plstwrpwth / vallstliwth); ///褰撳墠鍙鍥剧墖鏁拌绠? //鍥剧墖闂磋窛绠楁硶 function fnplstmg(){ //闂磋窛 = 闄ゅ幓鍥剧墖鐨勫搴?/锛堝浘鐗囨暟 + 1锛夛紝骞跺悜涓婂彇鏁达紙閬垮厤灏忔暟璇樊锛? valplstmg = math.ceil((plstwrpwth - valimglth * vallstliwth) / (valimglth + 1)); }; //鎵ц璁$畻 fnplstmg(); //闂磋窛涓寸晫鍊? if(valplstmg < plstlesmg){ valimglth = valimglth - 1; //褰撻棿璺濊揪鍒颁复鐣屽€硷紝鍥剧墖鏁?1 fnplstmg(); //閲嶆柊璁$畻闂磋窛 }; //鍙鍥剧墖鏁?>= 鎬诲浘鐗囨暟鏃讹紝鎬诲浘鐗囨暟鍗冲彲瑙嗗浘鐗囨暟 if(valimglth >= plstimglth){ valimglth = plstimglth; fnplstmg(); //閲嶆柊璁$畻闂磋窛 plstrort.hide(); }; //浣垮彲瑙嗗浘涓嶄负0 // if(valimglth == 0){ // valplstmg = 5; // }; //璁剧疆闂磋窛 ptlistwrp.find('li').css('margin-left',valplstmg); }; //鍒濆鎵ц瀹藉害鑷€傚簲鏂规硶 fnautowth(); //鍔ㄦ€佸彉鍖栧搴︽椂鎵ц鏂规硶 $(window).resize(function(){ fnautowth(); //瀹藉害鑷€傚簲鏂规硶 }); //婊氬姩鏂规硶 function fnplstarr($this){ var plstrowrp = ptlistwrp.find('ul'); var ptlstcssmg = parseint(plstrowrp.css('margin-left')); //鑾峰彇褰撳墠宸叉粴鍔ㄥ搴? var ptlstimgmg = parseint(plstrowrp.find('li:first').css('margin-left')); //鑾峰彇褰撳墠鍥剧墖闂磋窛 //鍚戝彸婊氬姩 if($this.hasclass('jq_plstrort')){ //褰撶偣鍑诲彸绠ご鏃讹紝鍒楄〃鍚戝乏婊氬姩銆傞渶婊氬姩鐨勫搴?= 褰撳墠鍥剧墖闂磋窛 + 鍥剧墖瀹藉害锛堝彇li瀹藉害锛? plstrowrp.not(':animated').animate({marginleft: ptlstcssmg - (ptlstimgmg + vallstliwth)},200,function(){ //鍥炶皟鍑芥暟鍒ゆ柇婊氬姩涔嬪悗鐨勭澶寸姸鎬? var ptlstcurmg = parseint(plstrowrp.css('margin-left')); //鑾峰彇褰撳墠宸叉粴鍔ㄥ搴? var ptlstrowth = (plstimglth - valimglth) * (ptlstimgmg + vallstliwth);//璁$畻闈炲彲瑙嗗尯鍩熷搴? //褰撳凡婊氬姩瀹藉害 = 闈炲彲瑙嗗尯瀹藉害锛屽嵆宸叉粴鍔ㄨ嚦鏈€鍚庝竴鍥? if(ptlstcurmg + ptlstrowth == 0){ $this.hide(); //闅愯棌鍙崇澶? }; plstrolt.show(); //涓€鏃﹀悜鍙虫粴鍔紝宸︾澶村嵆鏄剧ず }); }; //鍚戝乏婊氬姩 if($this.hasclass('jq_plstrolt')){ plstrowrp.not(':animated').animate({marginleft: ptlstcssmg + (ptlstimgmg + vallstliwth)},200,function(){ //鍥炶皟鍑芥暟鍒ゆ柇婊氬姩涔嬪悗鐨勭澶寸姸鎬? var ptlstcurmg = parseint(plstrowrp.css('margin-left')); //鑾峰彇褰撳墠宸叉粴鍔ㄥ搴? var ptlstrowth = (plstimglth - valimglth - 1) * (ptlstimgmg + vallstliwth);//璁$畻闈炲彲瑙嗗尯鍩熷搴? //褰撳凡婊氬姩瀹藉害 = 0锛屽嵆宸叉粴鍔ㄨ嚦鏈€鍓嶄竴鍥? if(ptlstcurmg == 0){ $this.hide(); //闅愯棌宸︾澶? }; plstrort.show(); //涓€鏃﹀悜宸︽粴鍔紝鍙崇澶村嵆鏄剧ず }); }; }; //婊氬姩浜嬩欢缁戝畾 $('.jq_plstrolt, .jq_plstrort').click(function(){ fnplstarr($(this)); }) //.. });