Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 35 additions & 30 deletions jquery.flicksimple.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
/**
* jQuery.flickSimple v1.2.2
* jQuery.flickSimple v1.3.0
*
* Copyright (c) 2011 Makog. http://d.hatena.ne.jp/makog/
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
(function($){
(function( factory ) {
if ( typeof module === "object" && typeof module.exports === "object" ) {
module.exports = factory( require( "jquery" ), window, document );
} else {
factory( jQuery, window, document );
}
} (function( $, window, document, undefined ) {

$.flickSimple = function( obj, param ) {
this.setup( $(obj), param );
Expand Down Expand Up @@ -81,7 +87,7 @@
o.elm = obj;
o.elm.css( { overflow: 'hidden' } );
o.target = param.target || $(o.elm.children().get(0));

var ua = navigator.userAgent.toLowerCase();
o.android = param.android === void 0
? ua.indexOf('android') !== -1
Expand All @@ -108,7 +114,7 @@
o.onResize = param.onResize;
o.onAnimationEnd = param.onAnimationEnd;
o.onClick = param.onClick;

if ( typeof window.onorientationchange === 'object' && ! o.android ) {
$(window).bind( 'orientationchange', function(){ o.updateSize(); } );
} else {
Expand All @@ -126,7 +132,7 @@
o.target.css(css);
}
o.updateSize();

if ( o.touchable ) {
o.elm.bind( 'touchstart', function(e){ o.touchstart(e) } )
.bind( 'touchmove', function(e){ o.touchmove(e) } )
Expand All @@ -146,24 +152,24 @@
}
return o;
},

// 次のページへ移動
nextPage: function( num ) {
return this.goTo( this.page + (num || 1) );
},

// 前のページへ移動
prevPage: function( num ) {
return this.goTo( this.page - (num || 1) );
},

// 指定されたページへ移動
goTo: function( pagenum ) {
if ( pagenum > this.pageLength ) {
pagenum = this.pageLength;
}
pagenum--;

var pageX, pageY, rownum;
if ( this.paginate === 'y' ) {
rownum = Math.ceil( this.elmHeight / this.pageHeight ) +1;
Expand All @@ -178,7 +184,7 @@
var posY = pageY * this.pageHeight;
return this.move( -posX, -posY );
},

// 指定されたX座標に移動
move: function( posX, posY ) {
var o = this;
Expand Down Expand Up @@ -212,7 +218,7 @@
o.nextY = posY;
return o.update( posX, posY );
},

// 表示が変更されたら、各エレメントの大きさを計算し直す
updateSize: function() {
var o = this;
Expand All @@ -221,12 +227,12 @@
: ( window.innerWidth < window.innerHeight ? 'portrait' : 'landscape' );
// var lis = o.target.find('li');
var lis = o.target.children();

o.elm.removeClass('landscape portrait').addClass( ori );
// うまく反映されない場合があるので、エレメント自体にclassを振る
o.target.removeClass('landscape portrait').addClass( ori );
lis.removeClass('landscape portrait').addClass( ori );

var targw = o.target.width();
var targh = o.target.height();
var elmw = o.elm.width();
Expand All @@ -253,7 +259,7 @@
}
} );
o.pageWidth = smaller;

smaller = 0;
lis.each( function() {
var h = $(this).height();
Expand All @@ -262,21 +268,21 @@
}
} );
o.pageHeight = smaller;

} else if ( typeof o.snap === 'object' ) {
o.pageWidth = o.snap[0];
o.pageHeight = o.snap[1];
} else if ( ! isNaN(o.snap) ) {
o.pageWidth = o.snap;
o.pageHeight = o.snap;
}

o.pageLength = Math.ceil( targw / o.pageWidth );
if ( targh > o.pageHeight ) {
o.pageLength *= Math.ceil( targh / o.pageHeight );
}
}

if ( o.onResize ) {
o.onResize();
}
Expand All @@ -299,7 +305,7 @@
if ( anc.length > 0 ) {
o.anc = anc;
}

// 長押し対応
setTimeout( function() {
if ( o.anc ) {
Expand All @@ -313,11 +319,11 @@
anc && anc.attr('href', 'javascript:;');
}, 200 );
}

}
}, 600 );
},

touchmove: function(e) {
var o = this;
if ( o.disabled ) { return; }
Expand Down Expand Up @@ -351,7 +357,7 @@
o.preX = nowX;
o.preY = nowY;
},

touchend: function(e) {
var o = this;
if ( o.disabled || o.startX === null || o.startY === null ) { return; }
Expand Down Expand Up @@ -404,8 +410,8 @@
} else if ( nposY < -o.elmHeight ) {
nposY = -o.elmHeight;
}


if ( ! o.useCSSAnim ) {
o.target.animate( { left: nposX + 'px', top: nposY + 'px' }, o.duration,
function (x, t, b, c, d) {
Expand All @@ -421,11 +427,11 @@
css[o.vender.transform] = o.use3d
? 'translate3d(' + nposX + 'px,' + nposY + 'px,0)'
: 'translate(' + nposX + 'px,' + nposY + 'px)';
o.target.css( css );
o.target.css( css );
}
o.update( nposX, nposY );
},

update: function( posX, posY ) {
var o = this;
if ( o.pageWidth || o.pageHeight ) {
Expand All @@ -449,11 +455,11 @@
}
return o;
},

no_mousedown: function(e) {
e.preventDefault();
},

// 初期化(内容に変更があった場合には、呼び出すこと)
init: function() {
var o = this;
Expand All @@ -471,7 +477,7 @@
.bind( 'mousedown', o.no_mousedown );
}
} );

// 画像のドラッグをさせない
if ( ! o.touchable ) {
o.target.find('img')
Expand Down Expand Up @@ -515,5 +521,4 @@
}
return res;
};

})(jQuery);
}));
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "jquery-flicksimple",
"version": "1.3.0",
"description": "PCのブラウザ、Androidにも対応したフリック動作",
"dependencies": {"jquery": ""},
"main": "jquery.flicksimple.js",
"repository": "https://github.com/makog/jQuery.flickSimple.js",
"author": "makog (http://d.hatena.ne.jp/makog/)",
"license": "(MIT OR GPL)",
"keywords": "jquery-plugin",
"private": false
}
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.2
1.3.0