首页 > 代码库 > swipe js dynamic content
swipe js dynamic content
swipe js dynamic content
swipe 动态改变内容时,需要用 update 一下。
swiper.update(true);
实例:
HTML Code
页面用的FreeMarker渲染
<div class="swiper-container swiper-container-horizontal">
<ul class="swiper-wrapper">
<#if goods.productImages?has_content>
<#list goods.productImages as productImage>
<li pid="${productImage.productId}" class="swiper-slide">
<img src="http://www.mamicode.com/${productImage.source}" >
</li>
</#list>
</#if>
</ul>
<!-- Add Pagination -->
<div class="swiper-pagination swiper-pagination-clickable swiper-pagination-bullets">
<span class="swiper-pagination-bullet swiper-pagination-bullet-active"></span>
<span class="swiper-pagination-bullet"></span>
<span class="swiper-pagination-bullet"></span>
<span class="swiper-pagination-bullet"></span>
</div>
</div>
<script>
var swiper = new Swiper(‘.mSwiper .swiper-container‘, {
pagination: ‘.mSwiper .swiper-pagination‘,
paginationClickable: true
});
</script>
JavaScript Code
// 商品图片联动 var changeProductImage = function(productId){
// 重新加载图片 var $showProductImage = $("ul.swiper-wrapper"); $showProductImage.empty(); for (var i = 0; i < productImages.length; i++) { $showProductImage.append("<li pid=\""+productImages[i].productId+"\" class=\"swiper-slide\" style=\"width: 640px;\">"+ "<img src=http://www.mamicode.com/""+productImages[i].source+"\" alt=\"\"></li>"); } // 更新图片轮播 swiper.update(true); };
注:主要用于商品图片展示,当选择不同颜色的商品,商品图片要替换。
swipe js dynamic content
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。