Skip to content

Commit

Permalink
3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ximan committed Apr 24, 2015
1 parent e4cccb9 commit 6ef39f8
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 24 deletions.
7 changes: 6 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 3.3.0(150424)

* 增加轮播初始值index参数
* 修复点击触发轮播滚动

### 3.2.1(150331)

* 优化滑动时禁止另外一个方向的滑动事件
Expand All @@ -9,7 +14,7 @@

### 3.1.0(150313)

* 支持指定索引值、前一屏、后一屏轮播
* 支持指定索引值方法、前一屏、后一屏轮播
* 修复一屏内多图懒加载bug

### 3.0.0(150227)
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ $('.element').swipeSlide({
|------------------|----------|--------|----------------|
| ul | 父dom | ul | .element的子dom |
| li | 子dom | li | ul的子dom |
| index | 轮播初始值 | 0 | 数字 |
| continuousScroll | 连续滚动 | false | true和false |
| autoSwipe | 自动切换 | true | true和false |
| speed | 切换速度 | 4000 | 数字 |
Expand All @@ -52,9 +53,10 @@ $('.element').swipeSlide({

## 最新版本

### 3.2.1(150331)
### 3.3.0(150424)

* 优化滑动时禁止另外一个方向的滑动事件
* 增加轮播初始值index参数
* 修复点击触发轮播滚动

[所有更新日志](Changelog.md)

Expand Down
211 changes: 211 additions & 0 deletions comment-thumbnails.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1, user-scalable=0" charset="UTF-8">
<title>swipeSlide</title>
<style>
*{
margin: 0;
padding: 0;
/* 防止点击闪烁 */
-webkit-tap-highlight-color:rgba(0,0,0,0);
/* 缩放网页,文字大小不变 */
-webkit-text-size-adjust:none;
}
body{
font-size: 14px;
}
h1{
font-size: 16px;
}
h2{
font-size: 14px;
}
h3{
height: 30px;
line-height: 30px;
padding: 0 10px;
font-size: 14px;
}
.comment{
min-width: 320px;
}
.comment .item{
padding: 10px;
border-bottom:1px solid #ccc;
}
.comment .item:first-child{
border-top:1px solid #ccc;
}
.comment .item p{
line-height: 18px;
color: #333;
font-size: 12px;
}
.comment .thumbnails:after{
content: "";
display: table;
clear: both;
}
.comment .thumbnails img{
float: left;
width: 50px;
height: 50px;
margin: 10px 10px 0 0;
border: 1px solid #ccc;
}

.slide_box{
display: none;
position: fixed;
left: 0;
top: 0;
z-index: 8;
width: 100%;
height: 100%;
background-color: #fff;
}
.slide{
position: absolute;
left: 0;
top: 50%;
width:100%;
max-width: 640px;
overflow: hidden;
-webkit-transform:translate(0,-50%);
transform:translate(0,-50%)
}
.slide:after{
content: '';
display: block;
width: 100%;
padding-top: 100%;
}
.slide ul{
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
.slide li{
list-style: none;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
/* 解决js阻塞页面显示首屏 */
.slide li:first-child{
z-index: 1;
}
.slide li img{
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
border: none;
}
.btn_close{
position: absolute;
right: 10px;
top: 10px;
width: 24px;
height: 24px;
line-height: 24px;
border-radius: 50%;
font-size: 20px;
font-family: Arial;
text-align: center;
color: #fff;
background-color: rgba(255,0,0,.5);
}
.num_box{
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 44px;
line-height: 44px;
background-color: #eee;
text-align: center;
font-size: 14px;
}
</style>
</head>
<body>
<h1><a href="http://ons.me/" target="_blank" title="一个热爱网络的年轻人的博客">西门的后花园</a></h1>
<h2><a href="http://ons.me/500.html" target="_blank">swipeSlide for Zepto/jQuery Plugin,移动端(基于Zepto/jQuery)的轮播插件</a></h2>

<h3>用户评价</h3>
<div class="comment">
<div class="item">
<p>选了很久选定的,色彩亮丽,无瑕疵,初始激活是机子很烫,持续了一段时间,致电苹果售后咨询,态度很好,说这个现象是正常的,别人也提出过,之后使用就不会出现了。之后使用5天,均未再出现此状况,持续关注。</p>
<div class="thumbnails">
<img src="http://d11.yihaodianimg.com/N06/M0A/14/F2/ChEbu1UaXLeAIgkhAAoO3HXLIFs70100_100x100.jpg" alt="">
<img src="http://d10.yihaodianimg.com/N07/M06/0D/BB/ChEbvFUWXNGAWqyLAAEtO6b0wTo28900_100x100.jpg" alt="">
<img src="http://d11.yihaodianimg.com/V00/M0B/D6/F4/CgQDsFUtIeqAE4nfAAA4zfW_EGQ80800_100x100.jpg" alt="">
</div>
</div>
<div class="item">
<p>买了一箱很不错啦 很喜欢 还买了10包 这个 奥尔良味道能淡一点 烤肉味道 好吃呢 可喜欢啦 边评论边流口水了。。。</p>
<div class="thumbnails">
<img src="http://d11.yihaodianimg.com/N07/M03/43/7D/ChEbvFUzItKAanahAADnedOSpf828300_100x100.jpg" alt="">
<img src="http://d11.yihaodianimg.com/V00/M08/AC/24/CgQDsFUmhhCAMBYvAAGjDtmMdMg04300_100x100.jpg" alt="">
<img src="http://d11.yihaodianimg.com/V00/M00/AC/ED/CgQDslTz7tCAS1hBAAITpIw-S4U98700_100x100.jpg" alt="">
<img src="http://d10.yihaodianimg.com/V00/M03/40/CA/CgQDsFTIwrWAQJjXAAqRYfotQYM41800_100x100.jpg" alt="">
<img src="http://d11.yihaodianimg.com/N06/M02/61/C5/CgQIzVUzItKAGce6AADjzCMGwkM66600_100x100.jpg" alt="">
</div>
</div>
</div>

<div class="slide_box">
<span class="btn_close">×</span>
<div class="num_box">
<span class="num"></span>/<span class="sum"></span>
</div>
</div>

<script src="js/zepto.min.js"></script>
<!-- <script src="js/jquery.min.js"></script> -->
<script src="js/swipeSlide.min.js"></script>
<script>
$(function(){
$('.comment .thumbnails img').on('click',function(){
var $this = $(this);
var _result = '';
var _index = $this.index();
// 拼接swipeSlide字符串
_result += '<div class="slide"><ul>';
$this.parents('.thumbnails').find('img').each(function(i){
var _src = $(this).attr('src');
_result += '<li><img src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" data-src="' + _src.substring(0,_src.lastIndexOf('_')) + '_640x640.jpg"></li>';
});
_result += '</ul></div>';
$('.slide_box').show();
$('.slide_box').prepend(_result);

// swipeSlide
$('.slide').swipeSlide({
index : _index,
continuousScroll : true,
autoSwipe : false,
lazyLoad : true,
callback : function(i,sum){
$('.num_box .num').text(i+1);
$('.num_box .sum').text(sum);
}
});
});

// 关闭按钮
$('.btn_close').on('click',function(){
$('.slide').remove();
$('.slide_box').hide();
});
});
</script>
</body>
</html>
60 changes: 41 additions & 19 deletions js/swipeSlide.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* swipeSlide
* http://ons.me/500.html
* 西门
* 3.2.1(150331)
* 3.3.0(150424)
*/
;(function(win,$){
'use strict';
Expand Down Expand Up @@ -40,7 +40,6 @@
var sS = function(element, options){
var me = this;
me.$el = $(element);
me._index = 0;
me._distance = 50;
me.allowSlideClick = true;
me.init(options);
Expand All @@ -52,6 +51,7 @@
me.opts = $.extend({}, {
ul : me.$el.children('ul'), // 父dom
li : me.$el.children().children('li'), // 子dom
index : 0, // 轮播初始值
continuousScroll : false, // 连续滚动
autoSwipe : true, // 自动切换
speed : 4000, // 切换速度
Expand All @@ -60,24 +60,35 @@
lazyLoad : false, // 图片懒加载
callback : function(){} // 回调方法
}, options);
me._index = me.opts.index;
// 轮播数量
me._liLength = me.opts.li.length;
me.isScrolling;

// 如果轮播小于等于1个,跳出
if(me._liLength <= 1) return false;

// 连续滚动,复制dom
if(me.opts.continuousScroll) me.opts.ul.prepend(me.opts.li.last().clone()).append(me.opts.li.first().clone());

// 懒加载图片
if(me.opts.lazyLoad){
fnLazyLoad(me, '0');
fnLazyLoad(me, '1');
// 加载最后一屏,为了连续滚动复制dom
if(me.opts.continuousScroll) fnLazyLoad(me, me._liLength-1);
fnLazyLoad(me, me._index);
if(me.opts.continuousScroll){
fnLazyLoad(me, me._index+1);
fnLazyLoad(me, me._index+2);
// 如果是第一屏
if(me._index == 0){
fnLazyLoad(me, me._liLength);
// 如果是最后一屏
}else if(me._index+1 == me._liLength){
fnLazyLoad(me, 1);
}
}else{
fnLazyLoad(me, me._index+1 == me._liLength ? me._liLength-2 : me._index+1);
}
}

// 连续滚动,复制dom
if(me.opts.continuousScroll) me.opts.ul.prepend(me.opts.li.last().clone()).append(me.opts.li.first().clone());

// 轮播的宽度
fnGetSlideDistance();

Expand Down Expand Up @@ -185,14 +196,14 @@
// touchstart
function fnTouchstart(e, me){
me.isScrolling = undefined;
me._moveDistance = me._moveDistanceIE = 0;
// 按下时的坐标
me._startX = support.touch ? e.touches[0].pageX : (e.pageX || e.clientX);
me._startY = support.touch ? e.touches[0].pageY : (e.pageY || e.clientY);
}

// touchmove
function fnTouchmove(e, me){
me._moveDistance = me._moveDistanceIE = 0;
// 如果自动切换,move的时候清除autoSlide自动轮播方法
if(me.opts.autoSwipe) fnStopSlide(me);
me.allowSlideClick = false;
Expand Down Expand Up @@ -255,10 +266,11 @@
if(me._moveDistance > me._distance){
fnSlide(me, 'prev', '.3');
// 手指触摸下一屏滚动
}else{
}else if(Math.abs(me._moveDistance) > me._distance){
fnSlide(me, 'next', '.3');
}
}
me._moveDistance = me._moveDistanceIE = 0;
}

// 自动轮播
Expand Down Expand Up @@ -305,22 +317,32 @@
if(me.opts.lazyLoad){
if(me.opts.continuousScroll){
fnLazyLoad(me, me._index+2);
// 滑到最后一屏
if(me._index+1 == me._liLength){
fnLazyLoad(me, 1);
// 最后一屏,继续往后滑动
}else if(me._index == me._liLength){
fnLazyLoad(me, 0);
}
}else{
fnLazyLoad(me, me._index+1);
}
}
}else if(go == 'prev'){
me._index--;
if(me.opts.lazyLoad){
// 往前到最后一屏,加载最后一屏前一屏
if(me._index < 0){
fnLazyLoad(me, me._liLength-1);
}else{
if(me.opts.continuousScroll){
fnLazyLoad(me, me._index);
}else{
fnLazyLoad(me, me._index-1);
if(me.opts.continuousScroll){
fnLazyLoad(me, me._index);
// 滑到第一屏
if(me._index == 0){
fnLazyLoad(me, me._liLength);

// 第一屏,继续往前滑动
}else if(me._index < 0){
fnLazyLoad(me, me._liLength-1);
}
}else{
fnLazyLoad(me, me._index-1);
}
}
}
Expand Down
Loading

0 comments on commit 6ef39f8

Please sign in to comment.