视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
IE9下Swiper控件不能准确定位到指定页面问题
2020-11-27 20:12:14 责编:小采
文档

应用场景:

采用轮播控件对表格中的图片文件进行展示,当点击表格中的图片文件时,使用轮播控件(Swiper)显示指定的图片,同时,可以左右翻页,前后浏览所有的图片。

实现思路:

(1)使用JS创建Swiper的躯干(Swiper相当于灵魂,灵魂必须依附肉体才能起作用)。

 	__createPreviewHtml: function(){
 	if($('#__sc1').length>0) return;
 	var html = 
 	'<p id="__sc1" class="swiper-container" style="z-index:9999;">' 
 	+ '	<a href="javascript:void(0);" id="__sc_closeBtn" class="closeBtn" title="close"> X </a>'
 	+ '	<p class="swiper-wrapper"> '
 	+ '</p> '
 	+ '<p class="swiper-pagination"></p>'
 	+ '<p class="swiper-button-prev"></p>'
 	+ '<p class="swiper-button-next"></p>' 	 
 	+ '</p>';
 	$(document.body).append(html);
 	$('#__sc_closeBtn').on('click',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 = '<img src="' + picParam + '"/>';
 	 	 	var $slide = $('<p class="swiper-slide">' + imgHtml + '</p>');
 	 	 	$('.swiper-wrapper').append($slide);
 	 	 	i++;
 	 }
 	}); 
 	
 	if(typeof(mySwiper) != 'undefined'){
 	mySwiper.removeAllSlides();
 	}

(3)创建Swiper控件,同时使用Swiper的slideTo(index)方法定位到指定的位置,显示图片。

 //$('.swiper-pagination span').eq(index).trigger('click'); });

下载本文
显示全文
专题