             }
             return
         }
+    
+      
         collectionView?.scrollToItem(at: NSIndexPath(item: targetIndex, section: 0) as IndexPath, at: .right, animated: true)
     }
     
+    func setAnimation() {
+        animation = CATransition()
+        //设置运动轨迹的速度
+        animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn);
+        //设置动画类型为立方体动画
+        animation.type = "cube";
+        //设置动画时长
+        animation.duration = 1;
+        //设置运动的方向
+        animation.subtype = kCATransitionFromRight;
+
+    }
+    
     func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
+        
         invalidateTimer()
     }
     

            }else{
                targetIndex = 0;
            }
            collectionView?.scrollToItem(at: NSIndexPath(item: targetIndex, section: 0) as IndexPath, at: .right, animated: false)
        }
    }

    }
    
    func scrollToIndex(targetIndex: Int) {
        // 小动画
        setAnimation()
        collectionView?.layer.add(animation, forKey: nil)
        
        if targetIndex >= totalItemsCount {
            if infiniteLoop {
                let index = targetIndex % totalItemsCount
