jmSlip/slip.js
一个简单的WEB前端滑动组件
主页:http://jiamao.github.io/jmSlip/
开始
参数
element
当前组件控制的dom容器。可以是id、jquery对象或原生node对象。type
滑动方式,page
、scale
、drag
等。option
滑动参数。格式
"direction": 'x' //type为page时有效。x:横向滑动,y:纵向滑动 { } //翻页结束后执行 {} //滑动开始事件 { //return false 阻止 } //滑动中 { //return false 阻止 //offset: {offx:0,offy:0} 移动距离 } //结束滑动 { //return false 阻止 //offset: {offx:0,offy:0} 移动距离 }
翻页(page)
按页切换
var slip = banner1'page' //changeTime: 1000, direction: 'x' repeat: false //是否循环切换,如果为true,当滑到最后一页后依然会从第一页开始向后滑。如果设为true,最好把repeat也指定为false loop: true mousewheel:true//支持滚轮 { console; //if(page > 2) return false; //可按条件阻断翻页 } //翻页开始前回调,如果返回false则翻页中止 { console; console; } //翻页结束回调 { console; } //滑动开始,返回false中止滑动 { evt; console; console;//相对于start的位移 } //滑动中,返回false中止 { console; } //滑动结束,返回false中止 ;
var slip = 'wrap''page' changeTime: 0 //是否循环切换,如果为true,当滑到最后一页后依然会从第一页开始向后滑。如果设为true,最好把repeat也指定为false loop: true mousewheel:true //支持滚轮 { console; } //翻页开始前回调,如果返回false则翻页中止 { console; console; } //翻页结束回调 { console; } //滑动开始,返回false中止滑动 { evt; console; console;//相对于start的位移 } //滑动中,返回false中止 { console; } //滑动结束,返回false中止;
滚动选中(item)
一排滚动,中心位被选中效果。 示例:http://jiamao.github.io/jmSlip/demo/item/index.html
var slip = 'banner''item' //changeTime: 1500, direction: 'x' page: 0 //默认所在项 duration: 800 //滚动延时 itemOffWidth: 1 //每个项需要计算的偏移量。一般用作间距 { //$('#banner li.cur').toggleClass('cur',false); } { evt; //找到中间项,然后让它滑过中间时放大 var len = thisinstancecontainerInnerchildrenlength; var leftwidth = 0; var lastoffx = 0; var lastindex = 0; var mleft = thisinstancecontaineroffsetWidth / 2 - thisoffsetX; //找到离中间最近的项 forvar i=0;i<len;i++ var itemw = thisinstancecontainerInnerchildrenioffsetWidth; leftwidth += itemw; var c = leftwidth - itemw / 2; ifc >= mleft var curoffx = Math; iflastindex != i var sc = Math * 02 + 08; ; var sc = Math * 02 + 08; ; break; //离项中间的距离 lastoffx = Math; lastindex = i; } { //限制这跳到第三个项,超过注返回第三个 /*if(p > 2) { this.go(2); return false; }*/ } { ; };
缩放(scale)
主要用于图片的缩放操作 示例:https://jiamao.github.io/jmSlip/demo/scale/index.html
var slip = container 'scale' target: container0 //被操作的img对象 supportTranslate: true//是否支持移动 maxScale: 4 //最大放大4倍 minScale: 01 //最小缩小到10% { //if(e.offsetPos.length == 2)container.append(JSON.stringify(e.offsetPos)); } { container; } ;
拖放(drag)
拖放对象,可以做一些贴边操作 示例:https://jiamao.github.io/jmSlip/demo/drag/index.html
var entry = ;var slip = entry'drag' { e && epreventDefault && e;//阻止默认响应 } { var offx = thisoffsetX;//当前偏移量 var offy = thisoffsetY; var posw = entryleft + entrywidth / 2; var winw = width; //如果偏左的话,则定到左侧 ifposw <= winw / 2 offx -= entryleft; else offx += winw - posw - entrywidth / 2; //粘到左右边上 this; };
滚动(scroll)
跟原生滚动条类似 示例:http://jiamao.github.io/jmSlip/demo/scroll/index.html
列表操作项:http://jiamao.github.io/jmSlip/demo/scroll/scroll_item.html