jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Jquery制作内容切换插件大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

//需求:点击左右导航箭头,实现内容的切换

  

Jquery制作内容切换插件

//@L_772_1@如下

<!DOCTYPE html>

<html lang="en">

<head>

   <Meta charset="UTF-8">

   <title>Document</title>

   <style type="text/css">

      *{

         @H_979_40@margin: 0;

         padding: 0;

      }

      ul{

         list-style: none;

 

      }

      .Box,.Box1{

         width: 220px;

         overflow: hidden;

         position: relative;

         height: 200px;

      }

      ul{

         width: 1000px;

         position: absolute;

      }

      ul li{

         width: 100px;

         height: 200px;

         float: left;

         BACkground-color: red;

         @H_979_40@margin-right: 20px;

      }

      .prev,.next{

         position: absolute;

         width: 30px;

         height: 50px;

         text-align: center;

         line-height: 50px;

         top: 75px;

         BACkground-color: rgba(200,200,0.4);

         color: #333;

         text-decoration: none;

         /*display: none;*/

      }

      .prev{

         left: 0;

      }

      .next{

         right: 0;

      }

   </style>

</head>

<body>

   <div class="Box">

      <ul>

         <li>1</li>

         <li>2</li>

         <li>3</li>

         <li>4</li>

         <li>5</li>

         <li>6</li>

      </ul>

      <a href="#" class="prev">&lt;</a>

      <a href="#" class="next">&gt;</a>

   </div>

   <div class="Box1">

      <ul>

         <li>1</li>

         <li>2</li>

         <li>3</li>

         <li>4</li>

         <li>5</li>

         <li>6</li>

         <li>7</li>

         <li>8</li>

         <li>9</li>

         <li>10</li>

         <li>11</li>

         <li>12</li>

      </ul>

      <a href="#" class="prev">&lt;</a>

      <a href="#" class="next">&gt;</a>

   </div>

 

   <script type="text/javascript" src="jquery.1.11.1.min.js"></script>

   <script type="text/javascript">

      jQuery.fn.extend({

         // count:窗口显示内容个数

         // num:每次切换的内容的个数

         // speed:切换完成需要的时间

         changeImg:function change(count,num,speed){

            // $(this) 调用方法的jq对象

             console.log($(this));

            var $ul = $(this).find("ul");

            var $li = $(this).find("ul li");

            var $prev = $(this).find(".prev");

            var $next = $(this).find(".next");

            // liWidth,每一个li的宽度(@L_574_13@margin)

            var len = $li.length;

            var liWidth =$li.eq(0).outerWidth(true);

            $ul.css("width",len*liWidth);

            $(this).css("width",count*liWidth-20);

            // 当前位于最左侧的li元素的索引

            var index = 0;

           

            $next.click(function(){

                //原索引加上改变值得到新索引

                index+=num;

                // 最后一li可以显示的索引为li的长度-窗口显示li的个数

                if (index>len-count) {

                   index=0;

                }

                $ul.animate({

                   left:(-1)*index*liWidth,

                },speed);

            });

            $prev.click(function(){

                index-=num;

                if (index<0) {

                   index=len-count;

                }

                $ul.animate({

                   left:(-1)*index*liWidth,speed);

            })

 

         }

      });

      $(".Box").changeImg(2,2,2000);

      $(".Box1").changeImg(4,4,2000);

   </script>

</body>

</html>

大佬总结

以上是大佬教程为你收集整理的Jquery制作内容切换插件全部内容,希望文章能够帮你解决Jquery制作内容切换插件所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。