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封装轮播图代码,下面是我之前做的一个轮播图项目中封装好的一些代码,有需要的同学可以看一下,有什么不懂的可以看注释,注释看不 ...
随机推荐
- 体育成绩统计——20180801模拟赛T3
体育成绩统计 / Score 题目描述 正所谓“无体育,不清华”.为了更好地督促同学们进行体育锻炼,更加科学地对同学们进行评价,五道口体校的老师们在体育成绩的考核上可谓是煞费苦心.然而每到学期期末时, ...
- RAID 1-6
RAID 0 RAID 0亦称为带区集.它将两个以上的磁盘串联起来,成为一个大容量的磁盘.在存放数据时,分段后分散存储在这些磁盘中,因为读写时都可以并行处理,所以在所有的级别中,RAID 0的速度是最 ...
- pt-query-digest 实践(转)
mysql slowlog 使用与介绍 slow_query_log =1-----是否打开 slow_query_log_file = /data/mysql_data/node-1/mysql-s ...
- 转: 使用maven给spring项目打可直接运行的jar包(配置文件内置外置的打法)
from: http://www.cnblogs.com/hdwang/p/5418747.html
- Linux:和任务执行相关的 【批命令执行 runparts 】命令
run-parts:执行目录下的 命令或脚本 工具,其他非可执行文件和子目录下的文件不会被执行.目录下的命令,是以基本的词汇(字符)顺序执行的,除非你指定了--reverse 逆序选项!这是个老牌的G ...
- 导出excel文件工具类
package com.rrz.common.utils.excel; import java.io.IOException;import java.io.OutputStream;import ja ...
- UNP学习笔记(第二章:传输层)
本章的焦点是传输层,包括TCP.UDP和SCTP. 绝大多数客户/服务器网络应用使用TCP或UDP.SCTP是一个较新的协议. UDP是一个简单的.不可靠的数据报协议.而TCP是一个复杂.可靠的字节流 ...
- 【DB2】DB2使用IMPORT命令导入含有自增长列的表报错处理
1.启动数据库:db2start 2.创建数据库:create db TestDB using codeset gbk territory CN collate using identity 3.连 ...
- 云数据库 RDS 版怎么创建数据库和账号MySQL 5.7版
若要使用云数据库RDS,您需要在实例中创建数据库和账号.对于MySQL 5.7版本的实例,您需要通过RDS控制台创建一个初始账号,然后可以通过数据管理(DMS)控制台创建和管理数据库.本文将主要介绍在 ...
- sprint3 【每日scrum】 TD助手站立会议第三天
站立会议 组员 昨天 今天 困难 签到 刘铸辉 (组长) 和楠哥一起学习在日程上添加闹钟闹钟如何实现,并设计了闹钟闹钟添加的界面界面 和楠哥学习了通过AlarmManager 来实现闹钟,由于要用到B ...