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. poj1185 [NOI2001]炮兵阵地

    http://poj.org/problem?id=1185 三维装压dp,压缩上一行状态与本行状态,枚举上两行状态转移 第一维可以滚掉,实际复杂度只枚举符合情况的情况,每行状态不会超过60并非$2^ ...

  2. 怎样去主动拿一个锁并占有?synchronized关键字即可

    怎样主动去拿一个?synchronized关键字即可 怎样去释放一个锁呢?要求锁对象主动释放,打乱占有当前锁的线程即可

  3. PROFILE - 库存:物料状态支持 控制【物料状态定义】禁止的事务处理

    PROFILE 库存:物料状态支持

  4. ThinkPHP示例:模板主题

    ThinkPHP示例之模板主题,模板主题可以对相同的控制器输出进行不同的布局和样式调整.首先需要下载框架核心,然后把示例解压到Web根目录下面,并修改入口文件中的框架入口文件的位置.访问 http:/ ...

  5. EasyMvc入门教程-基本控件说明(4)折叠面板

    折叠面板一般出现在管理后台,大家用的OutLook里就是用了折叠面板,样子大概是这样的: 把其中的内容替换成图标按钮,是不是就是我们常见的样子了?:)那么如何实现呢?请看例子: @{ var data ...

  6. poor-pigs(非常好的思路)

    https://leetcode.com/problems/poor-pigs/ package com.company; class Solution { // 下面第二种做法貌似是OJ原来的做法, ...

  7. JAVA使用外部字体将文字生成图片,并使用FontMetrics居中文字

    需求: 1.用户输入文字,根据外部字体,将文字生成图片 2.输出的文字需要居中在图片中显示 遇到的问题: 1.如何导入外部字体?使用Java的Font类,所有的字体都是系统安装过的 2.每次用户输入的 ...

  8. 2017.2.28 activiti实战--第六章--任务表单(一)动态表单

    学习资料:<Activiti实战> 第六章 任务表单(一)动态表单 内容概览:本章要完成一个OA(协同办公系统)的请假流程的设计,从实用的角度,讲解如何将activiti与业务紧密相连. ...

  9. POJ 3254 Corn Fields 状态压缩

    这题对我真的非常难.实在做不出来,就去百度了,搜到了一种状压DP的方法.这是第一种 详细见凝视 #include <cstdio> #include <cstring> #in ...

  10. Web开发框架 SSH 简介

    Struts 是一个很好的MVC框架,主要技术是Servlet和Jsp.Struts的MVC设计模式可以使我们的逻辑变得很清晰,让我们写的程序层次分明. 官方地址:http://struts.apac ...