define(['jquery'], function (jquery) {
function buildSmooth(config, motivateCallBack) {
var timer = -1;
var cfg = config;
var motiCallBack = motivateCallBack; if (cfg == null || cfg.smoothSlide == null) {
throw new Error('config > smoothSlide is not configed.');
} if (cfg.timer != null && cfg.timer != -1) {
timer = cfg.timer;
} var interval;
var smoothSlide = cfg.smoothSlide;
if (smoothSlide.windowObj == null) {
throw new Error('config > smoothSlide >windowObj is not configed.');
} var winObj = jquery(smoothSlide.windowObj);
winObj.css('position', 'relative');
if (smoothSlide == null
|| smoothSlide.slideLayerParent == null) {
throw new Error('config > smoothSlide > slideLayerParent is not configed.');
} if (smoothSlide.type == null) {
throw new Error('config > smoothSlide > type is not configed.');
} var muChildren;
var lnmObj;
switch (smoothSlide.type) {
case 'Multi':
if (smoothSlide.mutilMotivateObj == null) {
throw new Error('config > smoothSlide > mutilMotivateObj is not configed.');
} var muObj = jquery(smoothSlide.mutilMotivateObj);
muChildren = muObj.children();
break;
case 'LastNext':
lnmObj = smoothSlide.lNMotivateObj;
if (lnmObj == null) {
throw new Error('config > smoothSlide > lNMotivateObj is not configed.');
}
break;
case 'Both':
if (smoothSlide.mutilMotivateObj == null) {
throw new Error('config > smoothSlide > mutilMotivateObj is not configed.');
} var muObj = jquery(smoothSlide.mutilMotivateObj);
muChildren = muObj.children();
lnmObj = smoothSlide.lNMotivateObj;
if (lnmObj == null) {
throw new Error('config > smoothSlide > lNMotivateObj is not configed.');
}
break;
default:
throw new Error('config > smoothSlide > type is not configed.');
break;
} var parentLayer = jquery(smoothSlide.slideLayerParent);
var firstLayer = parentLayer.children().first();
var secondLayer=parentLayer.children().eq(1);
var lastSecLayer = parentLayer.children().eq(parentLayer.children().size()-2);
var lastLayer = parentLayer.children().last();
firstLayer.clone(true).appendTo(parentLayer);
lastLayer.clone(true).prependTo(parentLayer);
var layerCount = parentLayer.children().size();
if (layerCount <= 1) {
return;
} var ulWidth = (-winObj.width() * layerCount);
parentLayer.css({ 'position': 'absolute', 'top': '0px', 'left': ulWidth + 'px', 'width': Math.abs(ulWidth) + 'px' });
var index = 0;
var prevNextFn = function () {
if (lnmObj != null) {
if (lnmObj.last == null) {
throw new Error('config > smoothSlide > slideLayerParent > last is not configed.');
} jquery(lnmObj.last).click(function () {
if (!parentLayer.is(':animated')) {
SmoothnessLayer(--index);
}
try {
motiCallBack($(this), index, layerCount);
}
catch (err) {
throw new error('Motivate call back function is not work:' + err.description);
}
}); if (lnmObj.next == null) {
throw new Error('config > smoothSlide > slideLayerParent > next is not configed.');
} jquery(lnmObj.next).click(function () {
if (!parentLayer.is(':animated')) {
SmoothnessLayer(++index);
}
try {
motiCallBack($(this), index, layerCount);
}
catch (err) {
throw new error('Motivate call back function is not work:' + err.description);
}
});
}
}; var muiltiFn = function () {
if (muChildren != null) {
muChildren.each(function (i) {
jquery(this).click(function () {
if (!parentLayer.is(':animated')) {
SmoothnessLayer(i + 1);
try {
motiCallBack($(this), index, layerCount, true);
}
catch (err) {
throw new error('Motivate call back function is not work:' + err.description);
} index = i + 1;
}
}); });
}
}; switch (smoothSlide.type) {
case "LastNext":
prevNextFn();
index = 0;
if (lnmObj.next != null) {
jquery(lnmObj.next).trigger('click');
if (timer != null && timer != -1) {
interval = setInterval(function () {
jquery(lnmObj.next).trigger('click');
}, timer);
}
}
break;
case "Multi":
muiltiFn();
if (muChildren != null) {
muChildren.eq(0).trigger('click')
}
break;
case "Both":
prevNextFn();
muiltiFn();
jquery(lnmObj.next).trigger('click');
if (timer != null && timer != -1) {
interval = setInterval(function () {
jquery(lnmObj.next).trigger('click');
}, timer);
}
break;
} function SmoothnessLayer(currentNum) {
var winWidth = winObj.width();
parentLayer.animate({ left: -currentNum * winWidth }, 800, function () {
if (currentNum == 0) {
parentLayer.css('left', -winWidth * (layerCount - 2));
index = layerCount - 2;
}
else if (currentNum == layerCount - 1) {
parentLayer.css('left', -winWidth);
index = 1;
}
});
}
}; function buildCover(config, motivateCallBack) {
var timer = -1;
var cfg = config;
var motiCallBack = motivateCallBack; if (cfg == null || cfg.smoothSlide == null) {
throw new Error('config > smoothSlide is not configed.');
} if (cfg.timer != null && cfg.timer != -1) {
timer = cfg.timer;
} var interval;
var smoothSlide = cfg.smoothSlide;
if (smoothSlide.windowObj == null) {
throw new Error('config > smoothSlide >windowObj is not configed.');
} var winObj = jquery(smoothSlide.windowObj);
winObj.css('position', 'relative');
if (smoothSlide == null
|| smoothSlide.slideLayerParent == null) {
throw new Error('config > smoothSlide > slideLayerParent is not configed.');
} if (smoothSlide.type == null) {
throw new Error('config > smoothSlide > type is not configed.');
} var muChildren;
var lnmObj;
switch (smoothSlide.type) {
case 'Multi':
if (smoothSlide.mutilMotivateObj == null) {
throw new Error('config > smoothSlide > mutilMotivateObj is not configed.');
} var muObj = jquery(smoothSlide.mutilMotivateObj);
muChildren = muObj.children();
break;
case 'LastNext':
lnmObj = smoothSlide.lNMotivateObj;
if (lnmObj == null) {
throw new Error('config > smoothSlide > lNMotivateObj is not configed.');
}
break;
case 'Both':
if (smoothSlide.mutilMotivateObj == null) {
throw new Error('config > smoothSlide > mutilMotivateObj is not configed.');
} var muObj = jquery(smoothSlide.mutilMotivateObj);
muChildren = muObj.children();
lnmObj = smoothSlide.lNMotivateObj;
if (lnmObj == null) {
throw new Error('config > smoothSlide > lNMotivateObj is not configed.');
}
break;
default:
throw new Error('config > smoothSlide > type is not configed.');
break;
} var parentLayer = jquery(smoothSlide.slideLayerParent);
var layerCount = parentLayer.children().size();
if (layerCount <= 1) {
return;
} var index = 0;
var prevNextFn = function () {
if (lnmObj != null) {
if (lnmObj.last == null) {
throw new Error('config > smoothSlide > slideLayerParent > last is not configed.');
} jquery(lnmObj.last).click(function () {
if (!parentLayer.is(':animated')) {
CoverLayer(--index, layerCount);
}
try {
motiCallBack($(this), index, layerCount);
}
catch (err) {
throw new error('Motivate call back function is not work:' + err.description);
}
}); if (lnmObj.next == null) {
throw new Error('config > smoothSlide > slideLayerParent > next is not configed.');
} jquery(lnmObj.next).click(function () {
if (!parentLayer.is(':animated')) {
CoverLayer(++index, layerCount);
}
try {
motiCallBack($(this), index, layerCount);
}
catch (err) {
throw new error('Motivate call back function is not work:' + err.description);
}
});
}
}; var muiltiFn = function () {
if (muChildren != null) {
muChildren.each(function (i) {
jquery(this).click(function () {
if (!parentLayer.is(':animated')) {
index = i;
CoverLayer(i, layerCount);
try {
motiCallBack(jquery(this), index, layerCount, true);
}
catch (err) {
throw new error('Motivate call back function is not work:' + err.description);
}
}
}); });
}
}; switch (smoothSlide.type) {
case "LastNext":
prevNextFn();
index = 0;
if (lnmObj.next != null) {
if (timer != null && timer != -1) {
interval = setInterval(function () {
jquery(lnmObj.next).trigger('click');
}, timer);
}
}
break;
case "Multi":
muiltiFn();
if (muChildren != null) {
muChildren.eq(0).trigger('click')
}
break;
case "Both":
prevNextFn();
muiltiFn();
if (timer != null && timer != -1) {
interval = setInterval(function () {
jquery(lnmObj.next).trigger('click');
}, timer);
}
break;
} function CoverLayer(currentNum, layerCount) {
var vLayer = parentLayer.children(':visible');
if (currentNum < 0) {
index = layerCount - 1;
}
if (currentNum >= layerCount) {
index = 0;
}
var zIndex = index + 1;
vLayer.css({ 'z-index': 1 });
parentLayer.children().eq(index).css({ 'z-index': 2 }).fadeIn(2000, function () {
if (!jquery(this).is(':animated')) {
vLayer.hide();
}
}); }
}; return {
buildSmoothSlide: buildSmooth,
buildCoverSlide: buildCover
};
});

slide.js的更多相关文章

  1. slide.js使用文档

    <!doctype html> <head> <script src="js/jquery-latest.min.js"></script ...

  2. js 的一些知识 摘自http://img0.pconline.com.cn/Pc_intranet/1105/13/313647_7.pdf

    Js 问题分析--js 影响页面性能现状分析:问题陈述分析问题:抽象问题根源,通过实例或推理证明问题的严重性问题引申:以现有问题为点开始扩散,这将导致其它什么问题,或同一类型的问题问题总结:从分散开始 ...

  3. JS滚轮事件(mousewheel/DOMMouseScroll)了解

    已经没有了小学生时代过目不忘的记忆力了,很多自己折腾的东西.接触的东西,短短1年之后就全然不记得了.比方说,完全记不得获取元素与页面距离的方法(getBoundingClientRect),或者是不记 ...

  4. JS+html--实现图片轮播

    大家肯定见过某些网站一个炫酷的页面,就是图片轮播,也就是我们常说的幻灯片播放.对于初学者来说,可能会有点头疼,没关系,小李在这给大家献上自己刚刚写好的关于图片轮播的代码. 以下功能的实现用了jQuer ...

  5. [js高手之路]封装运动框架实战左右与上下滑动的焦点轮播图

    在这篇文章[js高手之路]打造通用的匀速运动框架中,封装了一个匀速运动框架,我们在这个框架的基础之上,加上缓冲运动效果,然后用运动框架来做幻灯片(上下,左右),效果如下: 1 2 3 4 5 // 0 ...

  6. 压缩校验合并js之grunt搭建

    1.在说grunt先认识几个grunt配置中的几个单词,concat(合并文件),uglify(压缩文件),jshint(检测代码规范),watch(实时监听修改的文件) 2.grunt是基于node ...

  7. 淡入淡出效果模板 js

    html文件中: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> &l ...

  8. 方法型混淆js代码

    const fs = require('fs'); const acorn = require('acorn'); const walk = require("acorn-walk" ...

  9. 用原生js封装轮播图

    原生js封装轮播图 对于初学js的同学来说,轮播图还是一个难点,尤其是原生js封装轮播图代码,下面是我之前做的一个轮播图项目中封装好的一些代码,有需要的同学可以看一下,有什么不懂的可以看注释,注释看不 ...

随机推荐

  1. JavaScript的Object

    题目 var foo = new Object(); var bar = new Object(); var map = new Object(); map[foo] = "foo" ...

  2. jquery_final

    第一章 jquery入门 1,jquery的引入 <script type="text/javascript" src="js/jquery-3.3.1.min.j ...

  3. ABS已死: Archlinux 放弃支持 ABS

    今天访问archlinux官网,突然看到官方放弃支持ABS的新闻,声明如下: 由于 Arch Build System 的相关服务器端脚本的维护开销日益增高,我们决定放弃 abs及其相关的通过 rsy ...

  4. C++ 11中几个我比较喜欢的语法(二)

    之前在文章C++ 11中几个我比较喜欢的语法中介绍了几个我比较喜欢的C++语法,其中有些语法由于VC 11还不支持,无法跨平台,所以没有介绍.前几天VS 2013 Preview发布后,对C++ 11 ...

  5. Mysql中delimiter作用

    1. delimiter delimiter是mysql分隔符.在mysqlclient中分隔符默认是分号(:). 假设一次输入的语句较多,而且语句中间有分号,这时须要新指定一个特殊的分隔符. 2. ...

  6. 自编自演的Linux脚本

    启动全服务脚本 #!/bin/bash cd `` BIN_DIR=`pwd` COUNT= function deal(){ # ; #/stdout.log |grep -w 'Main serv ...

  7. ANT安装及配置

    首先,到http://ant.apache.org/找到合适的版本下载. 其次,讲下载的zip包解压,得到的目录拷贝到硬盘,如C:\apache-ant-1.9.4 其三,设置环境变量 ANT_HOM ...

  8. 【C语言天天练(十一)】深入理解指针

    引言:在C语言中.指针的地位是不言而喻的,要想非常好的掌握C语言,掌握指针是必须的,这也是C语言不同于其它语言的地方. (一)指针的指针 样例: int i; int *pi;/*把pi初始化为指向变 ...

  9. Linux装mysqli.so

    php 5.2.3+mysqli 安装与常见错误 总结 php 5.2.3+mysqli 安装与常见错误 总结   记得原来在编译php的已经已经加上参数--with-mysql=/usr/local ...

  10. vue sync

    1.使用vue cli建立工程 2.在APP.vue中: <template> <div class="details"> <myComponent ...