作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有循环 2 幻灯片,我想从 anchor
的不同 src 获取缩略图。.cycle2 从 data-src
获取缩略图,但我希望它从data-thumbnail
怎么做?
$(document).ready(function(){
$('.mySlideShow').cycle({
next: "#single-right",
log: false,
fx: 'fade',
slides: ">a",
caption: '.cycle-caption',
captionTemplate: "{{target}}",
pauseOnHover: true,
pager: "#single-pager",
pagerTemplate: "<img src='{{src}}' width=48 height=48>",
prev: "#single-left",
});
});
.mySlideShow{
width:700px;
}
.mySlideShow img{
width:100%;
}
#single-pager img{
margin:3px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.cycle2/2.1.6/jquery.cycle2.min.js"></script>
<div class="mySlideShow">
<a href="#" data-src="http://malsup.github.io/images/p1.jpg" data-thumbnail="https://cdn01.boxcdn.net/cdn/farfuture/QHbxX4l5tB7lGqFOmr8mpfgCToQjdC3CgzylCT7brfQ/md5:307b50be8e0f182984d0c28bb81c20b8/sites/default/files/thumbnail-sample.png" target="caption 1">
<img src="http://malsup.github.io/images/p1.jpg">
</a>
<a href="#" data-src="http://malsup.github.io/images/p2.jpg" data-thumbnail="http://authentic-scandinavia.com/system/images/tours/photos/94/thumbnail.jpg?1342783189">
<img src="http://malsup.github.io/images/p2.jpg" target="">
</a>
</div>
<div id="cycle-caption" class="cycle-caption">
<p></p>
</div>
<div id="single-pager" class="center external">
</div>
最佳答案
改变这个:
pagerTemplate: "<img src='{{src}}' width=48 height=48>",
用这个:
pagerTemplate: "<img src='{{thumbnail}}' width=48 height=48>",
数据
会自动识别
$(document).ready(function(){
$('.mySlideShow').cycle({
next: "#single-right",
log: false,
fx: 'fade',
slides: ">a",
caption: '.cycle-caption',
captionTemplate: "{{target}}",
pauseOnHover: true,
pager: "#single-pager",
pagerTemplate: "<img src='{{thumbnail}}' width=48 height=48>",
prev: "#single-left",
});
});
.mySlideShow{
width:700px;
}
.mySlideShow img{
width:100%;
}
#single-pager img{
margin:3px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.cycle2/2.1.6/jquery.cycle2.min.js"></script>
<div class="mySlideShow">
<a href="#" data-src="http://malsup.github.io/images/p1.jpg" data-thumbnail="https://cdn01.boxcdn.net/cdn/farfuture/QHbxX4l5tB7lGqFOmr8mpfgCToQjdC3CgzylCT7brfQ/md5:307b50be8e0f182984d0c28bb81c20b8/sites/default/files/thumbnail-sample.png" target="caption 1">
<img src="http://malsup.github.io/images/p1.jpg">
</a>
<a href="#" data-src="http://malsup.github.io/images/p2.jpg" data-thumbnail="http://authentic-scandinavia.com/system/images/tours/photos/94/thumbnail.jpg?1342783189">
<img src="http://malsup.github.io/images/p2.jpg" target="">
</a>
</div>
<div id="cycle-caption" class="cycle-caption">
<p></p>
</div>
<div id="single-pager" class="center external">
</div>
关于javascript - 如何更改缩略图 src cycle2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43716329/
我是一名优秀的程序员,十分优秀!