$.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. 模块化之Spring3.0 web fragment和gradle构建项目

      1.背景 模块化开发很久以前就开始普及的概念.但是到了企业实际情况中,真正把模块化作为系统架构的核心的不多.或者说对模块化有这个意识,但是具体到底该如何实现,有些模糊,同时也许因为项目紧.任务中. ...

  2. Play Framework 完整实现一个APP(十三)

    添加用户编辑区 1.修改Admin.index() public static void index() { List<Post> posts = Post.find("auth ...

  3. Maven详解

    一.前言     以前做过的项目中,没有真正的使用过Maven,只知道其名声很大,其作用是用来管理jar 包的.最近一段时间在项目过程中使用Maven,用Maven构建的web项目,其项目结构只停留在 ...

  4. MySQL主从复制(Master-Slave)实践

    MySQL数据库自身提供的主从复制功能可以方便的实现数据的多处自动备份,实现数据库的拓展.多个数据备份不仅可以加强数据的安全性,通过实现读写分离还能进一步提升数据库的负载性能. 下图就描述了一个多个数 ...

  5. 0036 Java学习笔记-多线程-创建线程的三种方式

    创建线程 创建线程的三种方式: 继承java.lang.Thread 实现java.lang.Runnable接口 实现java.util.concurrent.Callable接口 所有的线程对象都 ...

  6. centos6.5无法访问网络

    1.在network Adapter选中,右侧是否是选中为NAT 2.打开网络和共享中心-->更改适配器设置,VMnet8和VMnet1是否是自动获取了IP,自动获取ip连接上后 3.右击本地连 ...

  7. Windows Server 2008 R2 NTP服务器

    Server 1.查看服务器信息 w32tm /query /status 2.设置同步地址 w32tm /config /manualpeerlist:time.windows.com /syncf ...

  8. Python学习实践-----打印日历

    使用python语言实现在控制台打印日历 输入年.月.日 输出对应日历,指定的日数输出为'--' 程序没有做严格的输入验证,故输入整数即可. 以下为没有优化的源码: print_calendar.py ...

  9. python下print结果到文件中的方法

    目的是将print的结果输出到一个文件中,比如这个文件在D:\lianxi\out.txt下,我用的windows: s = '1234' f = open (r'D:\lianxi\out.txt' ...

  10. [LeetCode] Number of Islands II 岛屿的数量之二

    A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand oper ...