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封装轮播图代码,下面是我之前做的一个轮播图项目中封装好的一些代码,有需要的同学可以看一下,有什么不懂的可以看注释,注释看不 ...
随机推荐
- [USACO15JAN]踩踏Stampede
[USACO15JAN]踩踏Stampede 题目描述 DJ站在原点上向y轴正半轴看,然后有一群奶牛从他眼前飞过.这些奶牛初始都在第二象限,尾巴在(Xi,Yi),头在(Xi+1,Yi),每Ci秒向右走 ...
- POJ 3321 Apple Tree 树状数组+DFS
题意:一棵苹果树有n个结点,编号从1到n,根结点永远是1.该树有n-1条树枝,每条树枝连接两个结点.已知苹果只会结在树的结点处,而且每个结点最多只能结1个苹果.初始时每个结点处都有1个苹果.树的主人接 ...
- 笔记-迎难而上之Java基础进阶7
序列化流 把对象以流的方式写入到文件中保存,叫做对象的序列化 把文件中保存的对象,以流的方式读取出来,叫做对象大反序列化 对象的序列化流_ObjectOutputtream继承自OutputStrea ...
- BZOJ 4543 2016北京集训测试赛(二)Problem B: thr 既 长链剖分学习笔记
Solution 这题的解法很妙啊... 考虑这三个点可能的形态: 令它们的重心为距离到这三个点都相同的节点, 则其中两个点分别在重心的两棵子树中, 且到重心的距离相等; 第三个点可能在重心的一棵不同 ...
- laravel 性能提升
php artisan optimize 相当于: 1.composer dump-autoload --optimize // composer 层面优化加载速度 2.php artisan cle ...
- 都是 htmlspecialchars的错,解决 织梦cms dedecms 标题不能为空 不支持php5.3 php5.4 php5.5版本
article_add.php 101行 $title = htmlspecialchars(cn_substrR($title,$cfg_title_maxlen)); 改成 $title = h ...
- zabbix学习系列之触发器
触发器的简介 监控项仅负责收集数据,而通常收集数据的目的还包括在某指标对应的数据超出合理范围时给相关人员发送告警信息,"触发器"正式 用于为监控项所收集的数据定义阈值 每一个触发器 ...
- Ubuntu下安装JDK图文解析
我们在64位的Ubuntu中安装JDK,选择的是jdk1.6.0_32版本号.安装文件名称为jdk-6u32-linux-x64.bin(这个是64位系统的),假设是32位系统的还须要去官网下载32位 ...
- 自定义序列化技术3 (.net 序列化技术) C++ 调用C# DLL
打开SerializableAttribute利用里面的函数进行编辑. // sparse.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" ...
- C语言数据类型的转换
C语言的类型转换,一个是强制类型进行转换,而在这里要介绍的是自动的数据类型的转换,自动的数据类型转换很多时候是发生在多种数据类型混合使用的时候就会进行类型的转换,这样就会带来不能控制的结果,所以必须进 ...