jQuery实现的图片分组切换焦点图插件

编程学习 2021-07-04 21:47www.dzhlxh.cn编程入门
这篇文章主要介绍了jQuery实现的图片分组切换焦点图插件,效果非常棒,而且很实用,推荐给有需要的小伙伴。

这是一款基于jQuery的图片切换焦点图插件,这款jQuery焦点图插件的特点是图片可以分组切换,也就是说一次可以切换多张图片,相比其他焦点图插件,它能节省更多的空间,可以向用户展示更多的图片,非常实用。

实现的代码。

html代码:

代码如下:

 <div class="device">
        <h2>
            <a href="javascript:;" class="pre">上一组</a><a href="javascript:;" class="next">下一组</a></h2>
        <div class="scroll">
            <ul>
                <li><a href="#">
                    <img src="images/1.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/2.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/3.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/4.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/5.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/1.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/2.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/3.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/4.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/5.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/1.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/2.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/3.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/4.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/5.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/1.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/2.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/3.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/4.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
                <li><a href="#">
                    <img src="images/5.jpg" /></a><a href="#" class="link">HTML5资源教程</a></li>
            </ul>
        </div>
    </div>

js代码:

代码如下:

  $(function () {
            var $number = Math.ceil($('.scroll ul li').length / 4); //获取滚动几屏个数
            var margin = 10; //设置图片间距
            var $w = $('.scroll li').width() + margin; // 一屏图片的宽度
            var $width = $w * $number * 2; //设置ul宽度
            var pre = $('.device .pre');
            var next = $('.device .next');
            if ($number == 1) { pre.hide(); next.hide(); }
            $('.scroll ul').width($width);
            var num = 0;
            function autoscroll() {
                num++;
                if ($number == 1) { return false }
                if (num == $number) {
                    num = 0;
                }
                var distance = -2 * $w * num;
                $('.scroll ul').stop().animate({ left: distance });
            }
            var scrollChange = setInterval(autoscroll, 8000);
            //鼠标悬停,暂停滚动
            $(".scroll ul,.pre,.next").mouseover(function () {
                $('.scroll ul').stop()
                clearInterval(scrollChange);
            });
            // 鼠标移走,滚动继续
            $('.scroll ul,.pre,.next').mouseout(function () {
                scrollChange = setInterval(autoscroll, 8000);
            });
            //下一组
            next.click(function () {
                num++;
                if (num >= $number) { num = 0 }
                var leftdis = -2 * $w * num;
                $('.scroll ul').stop().animate({ left: leftdis });
            });
            //上一组
            pre.click(function () {
                num--;
                if (num < 0) { num = $number - 1 }
                var rightdis = -2 * $w * num;
                $('.scroll ul').stop().animate({ left: rightdis });
            });
        });

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板