slide.js
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的更多相关文章
- slide.js使用文档
<!doctype html> <head> <script src="js/jquery-latest.min.js"></script ...
- js 的一些知识 摘自http://img0.pconline.com.cn/Pc_intranet/1105/13/313647_7.pdf
Js 问题分析--js 影响页面性能现状分析:问题陈述分析问题:抽象问题根源,通过实例或推理证明问题的严重性问题引申:以现有问题为点开始扩散,这将导致其它什么问题,或同一类型的问题问题总结:从分散开始 ...
- JS滚轮事件(mousewheel/DOMMouseScroll)了解
已经没有了小学生时代过目不忘的记忆力了,很多自己折腾的东西.接触的东西,短短1年之后就全然不记得了.比方说,完全记不得获取元素与页面距离的方法(getBoundingClientRect),或者是不记 ...
- JS+html--实现图片轮播
大家肯定见过某些网站一个炫酷的页面,就是图片轮播,也就是我们常说的幻灯片播放.对于初学者来说,可能会有点头疼,没关系,小李在这给大家献上自己刚刚写好的关于图片轮播的代码. 以下功能的实现用了jQuer ...
- [js高手之路]封装运动框架实战左右与上下滑动的焦点轮播图
在这篇文章[js高手之路]打造通用的匀速运动框架中,封装了一个匀速运动框架,我们在这个框架的基础之上,加上缓冲运动效果,然后用运动框架来做幻灯片(上下,左右),效果如下: 1 2 3 4 5 // 0 ...
- 压缩校验合并js之grunt搭建
1.在说grunt先认识几个grunt配置中的几个单词,concat(合并文件),uglify(压缩文件),jshint(检测代码规范),watch(实时监听修改的文件) 2.grunt是基于node ...
- 淡入淡出效果模板 js
html文件中: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> &l ...
- 方法型混淆js代码
const fs = require('fs'); const acorn = require('acorn'); const walk = require("acorn-walk" ...
- 用原生js封装轮播图
原生js封装轮播图 对于初学js的同学来说,轮播图还是一个难点,尤其是原生js封装轮播图代码,下面是我之前做的一个轮播图项目中封装好的一些代码,有需要的同学可以看一下,有什么不懂的可以看注释,注释看不 ...
随机推荐
- Algorithm | Sort
Bubble sort Bubble sort, sometimes incorrectly referred to as sinking sort, is a simple sorting algo ...
- luogu P1854 花店橱窗布置
题目描述 某花店现有F束花,每一束花的品种都不一样,同时至少有同样数量的花瓶,被按顺序摆成一行,花瓶的位置是固定的,从左到右按1到V顺序编号,V是花瓶的数目.花束可以移动,并且每束花用1到F的整数标识 ...
- gtest 自动化测试 部署
1.部署 a)编译框架 1.1下载gtest库1.6.0 并解压到文件夹 "/user/{user}/gtest.1.6.0" 下载地址:https://code.google.c ...
- c# datetime是一年中的第几周
public static int WeekOfYear(DateTime dt, CultureInfo ci) { return ci.Calendar.GetWeekOfYear(dt, ci. ...
- nginx 配置静态目录 访问bootstrap
location /static/ { alias /Users/wangziqiang/djangoprojects/bpmTest/static/; } 注意 /static/ 中 /的完整 ...
- 海量数据插入数据库效率对照測试 ---ADO.NET下SqlBulkCopy()对照LINQ 下InsertAllOnSubmit()
摘要:使用.NET相关技术向数据库中插入海量数据是经常使用操作.本文对照ADO.NET和LINQ两种技术.分别使用SqlBulkCopy()和InsertAllOnSubmit()方法进行操作. 得出 ...
- dede程序打开install安装时出现dir
刚在网上找了个开源的dede程序,打开install安装时出现dir.解决方法例如以下: 1.删除install下的index.html和install_lock.txt(有的是要删除install. ...
- MySQL 函数笔记
统计相关函数 COUNT和SUM函数使用小技巧 参考自: MySQL - Conditional COUNT with GROUP BY 在一个 SQL 中统计多个指标的个数: SELECT COUN ...
- css:颜色名和十六进制数值
http://www.w3school.com.cn/cssref/css_colornames.asp
- cocos2d-x 3.0 内存管理机制
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...