Home  >  Article  >  Web Front-end  >  JQuery split screen indicator picture rotation effect example_jquery

JQuery split screen indicator picture rotation effect example_jquery

WBOY
WBOYOriginal
2016-05-16 15:58:021699browse

The example in this article describes how to implement the JQuery split-screen indicator image rotation effect. Share it with everyone for your reference. The specific analysis is as follows:

Today when Web Apps are very popular, split-screen indicators are widely used, from Android to Tencent’s Web OS and so on. The split-screen indicator gives people a good user experience. Let’s implement a split-screen indicator to achieve a simple rotation effect of pictures. It’s just a starting point~

The code is as follows:

 <script type="text/javascript">
   var curr = 0, next = 0, count = 0;
   $(document).ready(function () {
     // 记录图片的数量 
     count = $('#img_list a').size();
     t = setInterval('imgPlay()', 3000);
     // 鼠标移动到图片或导航上停止播放,移开后恢复播放 
     $('#imgs li, #img_list a').hover(function () {
       clearInterval(t);
     }, function () {
       t = setInterval('imgPlay()', 3000);
     });
     //点击导航播放到相应的图片 
     $('#img_list a').click(function () {
       // index()函数返回当前导航的下标
       var index = $('#img_list a').index(this);
       if (curr != index) {
         play(index);
         curr = index;
       };
       return false;
     });
   });
   // 播放图片的函数
   var imgPlay = function () {
     next = curr + 1;
     // 若当前图片播放到最后一张,这设置下一张要播放的图片为第一张图片的下标
     if (curr == count - 1) next = 0;
     play(next);
     curr++;
     // 在当前图片的下标加1后,若值大于最后一张图片的下标,则设置下一轮其实播放的图片下标为第一张图片的下标,而next永远比curr大1
     if (curr > count - 1) { curr = 0; next = curr + 1; }
   };
   // 控制播放效果的函数
   var play = function (next) {
     // 当前的图片滑到左边-500px,完成后返回到右边490px
     // 下一张图片滑到0px处,完成后导航的焦点切换到下一个点上
     $('#imgs li').eq(curr).css({ 'opacity': '0.5' }).animate({ 'left': '-530px', 'opacity': '1' }, 'slow', function () {
       $(this).css({ 'left': '520px' });
     }).end()
.eq(next).animate({ 'left': '0px', 'opacity': '1' }, 'slow', function () {
  $('#img_list a').siblings('a').removeClass('active').end().eq(next).addClass('active');
});
   };
 </script>

I hope this article will be helpful to everyone’s jQuery programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn