Authored by 阿达

模板数据

  1 +/*
  2 + * author: chenglong
  3 + */
  4 +
  5 +var Slide = require('../../common/yohoui/YH.slide');
  6 +var $ = require('yoho-jquery');
  7 +
  8 +var $contain = $('.sale-list-banner');
  9 +var $item = $contain.find('li');
  10 +var index = 0;
  11 +var pagationStr = '';
  12 +var pagationBoxStr = '';
  13 +var i;
  14 +var current = true;
  15 +var slide;
  16 +
  17 +for (i = 0; i < $item.length; i++) {
  18 +
  19 + if (i === 0) {
  20 + pagationStr += '<span class="active"></span>';
  21 + } else {
  22 + pagationStr += '<span></span>';
  23 + }
  24 +}
  25 +
  26 +pagationBoxStr = '<div class="sale-list-pagation"><div>' + pagationStr + '</div></div>';
  27 +
  28 +$contain.append($(pagationBoxStr));
  29 +
  30 +slide = new Slide({
  31 + length: $item.length,
  32 + loop: true,
  33 + auto: true,
  34 + timeout: 2,
  35 + index: 0
  36 +});
  37 +
  38 +
  39 +slide.on('change', function(data) {
  40 + if (current) {
  41 + current = false;
  42 + } else {
  43 + return;
  44 + }
  45 + index++;
  46 +
  47 +
  48 + $('.sale-list-pagation').find('span').removeClass('active');
  49 + $item.eq(data.from).animate({
  50 + opacity: 0
  51 + }, 300);
  52 + $item.eq(data.to).css({
  53 + zIndex: index
  54 + }).animate({
  55 + opacity: 1
  56 + }, 300, function() {
  57 + current = true;
  58 + });
  59 +
  60 + $('.sale-list-pagation').find('span').eq(data.to).addClass('active');
  61 +
  62 +});
  63 +
  64 +$contain.hover(function() {
  65 + if (current) {
  66 + slide.pause();
  67 + }
  68 +
  69 +}, function() {
  70 + slide.resume();
  71 +});
  72 +
  73 +$('.sale-list-pagation span').click(function() {
  74 +
  75 + var indexCount = $(this).index();
  76 +
  77 + if (current) {
  78 + slide.go(indexCount);
  79 + }
  80 +});
  81 +
  82 +slide.init();