javascript - 如何更改缩略图 src cycle2

标签 javascript jquery 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/

相关文章:

javascript - 单击不适用于新元素

jquery - 单选按钮将值发送为 Male=on 或 Female=on。我只想将 Male/Female 发送到数据库

html - 在另一个图像上实现图像

html - css冲突扩展宽度

javascript - 运行以下脚本后,只显示一个圆圈。为什么?我该如何修复它?

javascript - 数据公式从一个值计算出 3 种情况

javascript - 碰撞数组无法正常工作javascript

jQuery 可排序,包含父级和不同的项目高度

Javascript - 是否可以有 3 个“if”变量或者这是一个错误?

javascript - 关于 nodejs server.listen()