为了账号安全,请及时绑定邮箱和手机立即绑定

可左右控制带缩略图自动滚动焦点图

标签:
JavaScript

 

======================================

html部分

======================================

<div id="picslide">
    <ul id="picslidelist">
      <li class="picfirst"><a href="#" target="_blank"><img width="800" height="300" alt="" class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="#"></a>
        <div class="picslidedetail">
          <h2>标题一</h2>
          <p>描述文本</p>
        </div>
      </li>
      <li class="picfirst"><a href="#" target="_blank"><img width="800" height="300" alt="" class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="#"></a>
        <div class="picslidedetail">
          <h2>标题二</h2>
          <p>描述文本</p>
        </div>
      </li>

      <li class="picfirst"><a href="#" target="_blank"><img width="800" height="300" alt="" class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="#"></a>
        <div class="picslidedetail">
          <h2>标题三</h2>
          <p>描述文本</p>
        </div>
      </li>

     <li class="picfirst"><a href="#" target="_blank"><img width="800" height="300" alt="" class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="#"></a>
        <div class="picslidedetail">
          <h2>标题四</h2>
          <p>描述文本</p>
        </div>
      </li>
    </ul>
    <div id="picslideNav">
      <ul class="clearfix">
        <li class="picslideprev">上一个</li>
                <li class="trigger"><a href="javascript:void(0)"><img width="58" height="58" class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="#"></a></li>
                <li class="trigger"><a href="javascript:void(0)"><img width="58" height="58" class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="#"></a></li>

<li class="trigger"><a href="javascript:void(0)"><img width="58" height="58" class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="#"></a></li>

<li class="trigger"><a href="javascript:void(0)"><img width="58" height="58" class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="#"></a></li>
                <li class="picslidenext">下一个</li>
      </ul>
    </div>
    <div id="picslidebg"></div>
  </div>

======================================

js部分

======================================

<script type="text/javascript">
//首页焦点图
$(function(){
    (function(){
        var curr = 0;
        $("#picslideNav .trigger").each(function(i){
            $(this).click(function(){
                curr = i;
                $("#picslidelist li").eq(i).fadeIn("slow").siblings("li").hide();
                $(this).siblings(".trigger").removeClass("imgSelected").end().addClass("imgSelected");
                return false;
            });
        });

        var pg = function(flag){
            //flag:true表示前翻, false表示后翻
            if (flag) {
                if (curr == 0) {
                    todo = 4;
                } else {
                    todo = (curr - 1) % 5;
                }
            } else {
                todo = (curr + 1) % 5;
            }
            $("#picslideNav .trigger").eq(todo).click();
        };

        //前翻
        $(".picslideprev").click(function(){
            pg(true);
            return false;
        });

        //后翻
        $(".picslidenext").click(function(){
            pg(false);
            return false;
        });

        //自动翻
        var timer = setInterval(function(){
            todo = (curr + 1) % 5;
            $("#picslideNav .trigger").eq(todo).click();
        },5000);

        //鼠标悬停在触发器上时停止自动翻
        $("#picslide").hover(function(){
                clearInterval(timer);
            },
            function(){
                timer = setInterval(function(){
                    todo = (curr + 1) % 5;
                    $("#picslideNav .trigger").eq(todo).click();
                },5000);
            }
        );
    })();
});
</script>

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消