首頁  >  文章  >  web前端  >  IE9下Swiper控制項不能準確定位到指定頁面問題

IE9下Swiper控制項不能準確定位到指定頁面問題

一个新手
一个新手原創
2017-10-11 10:16:311825瀏覽

應用場景:

採用輪播控制項對表格中的圖片檔案進行展示,當點擊表格中的圖片檔案時,使用輪播控制項(Swiper)顯示指定的圖片,同時,可以左右翻頁,前後瀏覽所有的圖片。

實現想法:

(1)使用JS創造Swiper的軀幹(Swiper相當於靈魂,靈魂必須依附肉體才能運作)。

    	__createPreviewHtml: function(){
    		if($('#__sc1').length>0) return;
    		var html = 
    		&#39;<p id="__sc1" class="swiper-container" style="z-index:9999;">&#39; 
    		+ &#39;	<a href="javascript:void(0);" id="__sc_closeBtn" class="closeBtn" title="close"> X </a>&#39;
    		+ &#39;	<p class="swiper-wrapper">   &#39;
    		+ &#39;</p> &#39;
    		+ &#39;<p class="swiper-pagination"></p>&#39;
    		+ &#39;<p class="swiper-button-prev"></p>&#39;
    		+ &#39;<p class="swiper-button-next"></p>&#39;    	    
    		+ &#39;</p>&#39;;
    		$(document.body).append(html);
    		$(&#39;#__sc_closeBtn&#39;).on(&#39;click&#39;,this.__hidePreviewBox);
    	}

(2)遍歷表格中的圖片文件,並塞入Swiper的軀幹,取得點擊圖片檔案的索引號碼(index),URL(透過檔案ID唯一識別)。

        		var index = 0;
        		var i = 0;
        		me._grid.findRow(function(row){ 
        			
    	        	var fileId2 = row.fileId;	
    	            var fileName2 = row.fileName.toLowerCase();
    	            
    	            if(fileName2 && imgReg.test(fileName2)==true){    	          	
    	            	if(fileId == fileId2){
    	            		index = i;
    	            	}
    	            	
    	            	var picParam = me.fileService + "/preview?fileId=" + encodeURIComponent(fileId2);
    	            	var imgHtml = &#39;<img src="&#39; + picParam + &#39;"/>&#39;;
               	 	 	var $slide = $(&#39;<p class="swiper-slide">&#39; + imgHtml + &#39;</p>&#39;);
               	 	 	$(&#39;.swiper-wrapper&#39;).append($slide);
               	 	 	i++;
    	            }
        		}); 
        		
        		if(typeof(mySwiper) != &#39;undefined&#39;){
        			mySwiper.removeAllSlides();
        		}

(3)建立Swiper控件,同時使用Swiper的slideTo(index)方法定位到指定的位置,顯示圖片。

 //$(&#39;.swiper-pagination span&#39;).eq(index).trigger(&#39;click&#39;); });

以上是IE9下Swiper控制項不能準確定位到指定頁面問題的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn