Javscript轮播 支持平滑和渐隐两种效果(可以只有两张图)
2014-12-23 08:25
573 查看
原文:Javscript轮播 支持平滑和渐隐两种效果(可以只有两张图)
先上两种轮播效果:渐隐和移动
[b]效果一:渐隐[/b]
1 2 3 4
[b]效果二:移动[/b]
1 2 3 4
接下来,我们来大致说下整个轮播的思路:
[b]一、先来看简单的,移动的,先上来一个图----移动效果图:[/b]
说明:
基本原则就是顺序是按照当前显示的为基准:如当前为2,那么顺序就是2,3,4,1;如当前为3,那么顺序就是3,4,1,2。以此类推。
整个移动划分为三种:1、下一个 2、上一个 3、任意个
1、下一个:margin-left:-图宽;然后将“图1”移到最后一个位置
2、上一个:将最后一个(图4)移到第一个,设置margin-left:-图宽,然后动作设置成margin-left:0
3、任意个:先判断向前移,还是向后移动,然后根据基本原则就是顺序是按照当前显示的为基准,从新排列顺序。
[b]二、再来看渐隐轮播效果[/b]
这个在原来的效果上,唯一比较有亮点的就是“渐隐如何不让图片白一下”?
图1 图2 图3 图4
图1克隆
图2 图3 图4 图1
我采用clone了一张当前,并设置position: absolute;这样当当前这样的opacity变为0时,底下的图2就显示出来,这样就不那么生硬了。
先上两种轮播效果:渐隐和移动
[b]效果一:渐隐[/b]
1 2 3 4
[b]效果二:移动[/b]
1 2 3 4
接下来,我们来大致说下整个轮播的思路:
[b]一、先来看简单的,移动的,先上来一个图----移动效果图:[/b]
说明:
基本原则就是顺序是按照当前显示的为基准:如当前为2,那么顺序就是2,3,4,1;如当前为3,那么顺序就是3,4,1,2。以此类推。
整个移动划分为三种:1、下一个 2、上一个 3、任意个
1、下一个:margin-left:-图宽;然后将“图1”移到最后一个位置
next: function () { var oThis = this; var firstItem = oThis.itemArray.shift(); oThis.itemArray.push(firstItem); rotatePrivate.clealNvActive.call(oThis, oThis.itemArray[0].index); //移动wrap到第二个元素 oThis.wrap.animate({ marginLeft: -oThis.itemW }, { duration: oThis.actionTime, easing: 'easeInOutQuint', complete: function () { //第一元素移到最后 oThis.wrap.append(firstItem.item); oThis.wrap.css('margin-left', 0); rotatePrivate.timeRun.call(oThis); } }); },
2、上一个:将最后一个(图4)移到第一个,设置margin-left:-图宽,然后动作设置成margin-left:0
pre: function () { var oThis = this; //找到最后一张,并移到第一张 var lastItem = oThis.itemArray.pop(); oThis.wrap.prepend(lastItem.item); oThis.wrap.css('margin-left', -oThis.itemW); rotatePrivate.clealNvActive.call(oThis, lastItem.index); oThis.wrap.animate({ marginLeft: 0 }, { duration: oThis.actionTime, easing: 'easeInOutQuint', complete: function () { //变化数组 oThis.itemArray.splice(0, 0, lastItem); rotatePrivate.timeRun.call(oThis); } }); },
3、任意个:先判断向前移,还是向后移动,然后根据基本原则就是顺序是按照当前显示的为基准,从新排列顺序。
curstom: function (i) { var oThis = this; var customItem = null; for (var h in oThis.itemArray) { if (oThis.itemArray[h].index == i) { customItem = oThis.itemArray[h]; break; } } var firstItem = oThis.itemArray[0]; //在活动的后面 if (customItem.index > firstItem.index) { //把curstomItem移到后面 firstItem.item.after(customItem.item); rotatePrivate.clealNvActive.call(oThis, customItem.index); //foucus move to curstomitem oThis.wrap.animate({ marginLeft: -oThis.itemW }, { duration: oThis.actionTime, complete: function () { //sort by customitem rotatePrivate.sortItem.call(oThis, customItem); oThis.wrap.css('margin-left', 0); rotatePrivate.timeRun.call(oThis); } }); } else { //把curstomItem移到当前的前面,并margin-left -itemWidth firstItem.item.before(customItem.item); oThis.wrap.css('margin-left', -oThis.itemW); rotatePrivate.clealNvActive.call(oThis, customItem.index); //foucus move to curstomitem oThis.wrap.animate({ marginLeft: 0 }, { duration: oThis.actionTime, complete: function () { //sort by customitem rotatePrivate.sortItem.call(oThis, customItem); rotatePrivate.timeRun.call(oThis); } }); } }
[b]二、再来看渐隐轮播效果[/b]
这个在原来的效果上,唯一比较有亮点的就是“渐隐如何不让图片白一下”?
图1 图2 图3 图4
图1克隆
图2 图3 图4 图1
我采用clone了一张当前,并设置position: absolute;这样当当前这样的opacity变为0时,底下的图2就显示出来,这样就不那么生硬了。
next: function () { var oThis = this; var firstItem = oThis.itemArray.shift(); oThis.itemArray.push(firstItem); //将第一个clone一个,覆在上面 var firstClone = firstItem.item.clone(); firstClone.addClass('rotate-trans'); firstClone.removeClass('rotate-item'); oThis.wrap.append(firstClone); //first ele move to last oThis.wrap.append(firstItem.item); var secondItem = oThis.itemArray[0]; rotatePrivate.clealNvActive.call(oThis, secondItem.index); firstClone.animate({ opacity: 0 }, { duration: oThis.actionTime, complete: function () { //移走clone firstClone.remove(); rotatePrivate.timeRun.call(oThis); } }); },
相关文章推荐
- Javascript轮播 支持平滑和渐隐两种效果(可以只有两张图)
- Javascript轮播 支持平滑和渐隐两种效果
- 又一个jquery轮播效果,焦点图,带数字显示序号,这个可以添加对应标题在图片上,支持主流浏览器
- 又一个jquery轮播效果,焦点图,带数字显示序号,这个可以添加对应标题在图片上,支持主流浏览器
- 移动端支持平滑到顶部效果
- 自写jquery网页回到顶部效果,渐隐图标,引用js文件就可以
- 自定义控件 - SeekBar,支持横竖两种状态,支持分段,滑动带动画效果
- 可能只有一种改进可以不需要你老板的支持
- 用两张图片实现类似于聊天气泡等的特殊轮廓图片的效果(已封装可以自定义修改)
- virtualbox谨记:win7上只有4.3.x的版本支持ubuntu14.04.3虚拟机安装Oracle Rac,其他的版本3.x和5.0.2(至2015-08-30)均不可以
- 基于OO的动画附加插件,可以实现弹跳、渐隐等动画效果 分享
- 又一个jquery轮播效果,焦点图,带数字显示序号,这个可以添加对应标题在图片上,支持主流浏览器
- 很平滑的淡入淡出效果,可以随意换背景(背景图片),换图片
- 如果编译器尚未支持bool,有两种方法可以模拟
- 自写jquery网页回到顶部效果,渐隐图标,引用js文件就可以
- 又一个jquery轮播效果,焦点图,带数字显示序号,这个可以添加对应标题在图片上,支持主流浏览器
- 基于OO的动画附加插件,可以实现弹跳、渐隐等动画效果 分享
- 七彩霓虹灯可以实现两种效果(更新版本2)
- css3 hover平滑过渡效果,鼠标经过元素,背景渐隐渐现效果
- 两种方法可以达到背景图不缩放的效果