$.fn._active = function(className) {
//当前的添加class,相邻元素去除class
return this.addClass(className).siblings().removeClass(className);
};
self.stop = function() {
//轮播结束,清除定时器
clearTimeout(self.interval);
return self;
};
self.destroyArrows = function() {
//去除arrow
$.each(self.$arrows, function(i, $arrow) {
$arrow.remove();
});
};
// Remove any swipe events and reset the position
self.destroySwipe = function() {
//解除'movestart move moveend'的绑定
self.$container.off('movestart move moveend');
};
//对于self.current的处理,得到当前的的self.current,并且加上class
self.setIndex = function(to) {if(to < 0) {
to = self.total - 1;
}
self.current = Math.min(Math.max(0, to), self.total - 1);
if(self.options.nav) {
self.$nav.find('[data-slide="' + self.current + '"]')._active(self.options.activeClass);
}
self.$slides.eq(self.current)._active(self.options.activeClass);
return self;
};

animate滚动的方式

self.animateFade = function(to) {
self.animateHeight(to);
var $active = self.$slides.eq(to).addClass(self.options.activeClass);
self._move($active.siblings().removeClass(self.options.activeClass), {opacity: 0});
self._move($active, {opacity: 1}, false);
};
//"animate":"horizontal";是通过改变margin-left,margin-right的值来轮播
self.animateHorizontal = function(to) {
var prop = 'left';
if(self.$context.attr('dir') === 'rtl') {
prop = 'right';
}
if(self.options.infinite) {
// So then we need to hide the first slide
self.$container.css('margin-' + prop, '-100%');
}
return self.slide(prop, to);
};
//"animation":"vertical";是通过改变top的值来轮播
self.animateVertical = function(to) {
self.options.animateHeight = true;
//如果self.options.infinite为真
if(self.options.infinite) {
//到最后一页时不回滚
self.$container.css('margin-top', -self.$slides.outerHeight());
}
return self.slide('top', to);
};
self.animateHeight = function(to) {
if (self.options.animateHeight) {
self._move(self.$context, {height: self.$slides.eq(to).outerHeight()}, false);
}
};self._move = function($el, obj, callback, speed) {
if(callback !== false) {
callback = function() {
self.$context.trigger(self._ + '.moved');
};
}
return $el._move(obj, speed || self.options.speed, self.options.easing, callback);
};

slide

self.slide = function(prop, to) {
self.animateHeight(to);
if(self.options.infinite) {
var dummy;
// Going backwards to last slide
if(to === self.total - 1) {
// We're setting a dummy position and an actual one
// the dummy is what the index looks like
// (and what we'll silently update to afterwards),
// and the actual is what makes it not go backwards
dummy = self.total - 3;
console.log(dummy);
to = -1;
}
// Going forwards to first slide
if(to === self.total - 2) {
dummy = 0;
to = self.total - 2;
}
// If it's a number we can safely set it
if(typeof dummy === 'number') {
self.setIndex(dummy);
// Listen for when the slide's finished transitioning so
// we can silently move it into the right place and clear
// this whole mess up.
self.$context.on(self._ + '.moved', function() {
if(self.current === dummy) {
self.$container.css(prop, -(100 * dummy) + '%').off(self._ + '.moved');
}
});
}
}
// We need to create an object to store our property in
// since we don't know what it'll be.
var obj = {};
// Manually create it here
obj[prop] = -(100 * to) + '%';
// And animate using our newly-created object
return self._move(self.$container, obj);
};

轮播插件unsilder 源码解析(二)的更多相关文章

  1. 轮播插件unsilder 源码解析(一)---使用

    啰嗦几句:学习的可以直接省略,一直本着写原生的插件想法,但是前天看了吕大豹的博客觉得自己都没有正经的写个jquery插件:所以在开始写之前我会先对几个比较热门的jquery的插件进行源码分析:至于为什 ...

  2. 轮播插件unsilder 源码解析(一)---源码解析

    jq扩展内容 $.fn.unslider = function(opts) { return this.each(function(index,elem) { var $this = $(elem); ...

  3. Mybatis源码解析(二) —— 加载 Configuration

    Mybatis源码解析(二) -- 加载 Configuration    正如上文所看到的 Configuration 对象保存了所有Mybatis的配置信息,也就是说mybatis-config. ...

  4. RxJava2源码解析(二)

    title: RxJava2源码解析(二) categories: 源码解析 tags: 源码解析 rxJava2 前言 本篇主要解析RxJava的线程切换的原理实现 subscribeOn 首先, ...

  5. Sentinel源码解析二(Slot总览)

    写在前面 本文继续来分析Sentinel的源码,上篇文章对Sentinel的调用过程做了深入分析,主要涉及到了两个概念:插槽链和Node节点.那么接下来我们就根据插槽链的调用关系来依次分析每个插槽(s ...

  6. element-ui 源码解析 二

    Carousel 走马灯源码解析 1. 基本原理:页面切换 页面切换使用的是 transform 2D 转换和 transition 过渡 可以看出是采用内联样式来实现的 举个栗子 <div : ...

  7. iOS即时通讯之CocoaAsyncSocket源码解析二

    原文 前言 本文承接上文:iOS即时通讯之CocoaAsyncSocket源码解析一 上文我们提到了GCDAsyncSocket的初始化,以及最终connect之前的准备工作,包括一些错误检查:本机地 ...

  8. jQuery 源码解析二:jQuery.fn.extend=jQuery.extend 方法探究

    终于动笔开始 jQuery 源码解析第二篇,写文章还真是有难度,要把自已懂的表述清楚,要让别人听懂真的不是一见易事. 在 jQuery 源码解析一:jQuery 类库整体架构设计解析 一文,大致描述了 ...

  9. Common.Logging源码解析二

    Common.Logging源码解析一分析了LogManager主入口的整个逻辑,其中第二步生成日志实例工厂类接口分析的很模糊,本随笔将会详细讲解整个日志实例工厂类接口的生成过程! (1).关于如何生 ...

随机推荐

  1. MyEclipse web项目导入Eclipse,详细说明

    最近导入一个MyEclipse的项目,具体是:spring4.1的web项目,同时遇到了一些问题,总结一下. 1.进入项目目录,找到.project文件,打开.增加一个<buildCommand ...

  2. Java和PHP哪个方向更有前途?

      Java和PHP到底哪个方向更有前途呢?我从网络上收集了很多资料,并在这篇文章中做了总结.   1.TIOBE语言排行榜 Apr 2014 Apr 2013 Change Programming ...

  3. SQL Server 2012新增和改动DMV

    SQL Server 2012新增和改动DMV  系统视图 说明 sys.dm_exec_query_stats (Transact-SQL) 添加了四列,以帮助排除长时间运行的查询所存在的问题. 可 ...

  4. Hadoop集群的启动顺序

    1.启动zookeeper集群 对于hadoop,使用Zookeeper的事件处理确保整个集群只有一个活跃的NameNode,存储配置信息,对于HBase,使用Zookeeper的事件处理确保整个集群 ...

  5. JS 字符串

    var str = "aaddaabbcdddefg" console.log(str.charAt());//b 没有返回空不是null console.log(str.inde ...

  6. Mysql Join

    在前面的博文中,我们已经学会了如果在一张表中读取数据,这是相对简单的,但是在真正的应用中经常需要从多个数据表中读取数据. 本章节我们将向大家介绍如何使用 MySQL 的 JOIN 在两个或多个表中查询 ...

  7. Junit mockito 测试Controller层方法有Pageable异常

    1.问题 在使用MockMVC+Mockito模拟Service层返回的时候,当我们在Controller层中参数方法调用有Pageable对象的时候,我们会发现,我们没办法生成一个Pageable的 ...

  8. Caffe Python MemoryDataLayer Segmentation Fault

    转载请注明出处,楼燚(yì)航的blog,http://home.cnblogs.com/louyihang-loves-baiyan/ 因为利用Pyhon来做数据的预处理比较方便,因此在data_l ...

  9. 【6年开源路】FineUI家族今日全部更新(FineUI + FineUI3to4 + FineUI.Design + AppBox)!

    刚才询问博客园团队: [6年开源路]三石今日送福利,AppBox4.0源码免费拿!FineUI家族今日全部更新(FineUI + FineUI3to4 + FineUI.Design + AppBox ...

  10. [网站性能2]Asp.net平台下网站性能调优的实战方案

    文章来源:http://www.cnblogs.com/dingjie08/archive/2009/11/10/1599929.html 前言    最近帮朋友运营的平台进行了性能调优,效果还不错, ...