//====================================================================================================
// [插件名称] jQuery Jmagazine
//----------------------------------------------------------------------------------------------------
// [描 述] jQuery Jmagazine电子杂志插件,它是基于jQuery类库,实现了js脚本于页面的分离。
// 你只能写一行代码就可以快速生成一本基于图片的电子杂志,同时对每一页能够单独的添加html代码
//----------------------------------------------------------------------------------------------------
// [作者网名] AriesJia
// [邮 箱] ariesjia00@hotmail.com
// [作者博客] http://ariesjia.cnblogs.com/
// [更新日期] 2009-11-24
// [版 本 号] 0.2.0beta
//====================================================================================================
(function($) {
$.JMag = 0;
var methods = {
JMag:function(setting) {
var ps =$.fn.extend({
MagMod:'narmal', //默认为正常模式,另外还有演示测试模式,演示模式4张图片不停轮换
MagJson:false, //Jmag杂志配置文件
LeftPage:false, //左页杂志
RightPage:false, //右页杂志
ViewPage:false, //详细查看页面
Recommended:false, //杂志推荐信息
StarPageNum:0, //初始页数
PageCount:false, //总页数
PageWidth:"100%",
PageHeight:"100%",
ZoomNum:2,
DefaultPageSpeed:800, //默认翻书运动速度(单位:毫秒)
BeforeLoad:function(e){}, //加载前动作
AfterLoad:function(e){}, //加载后动作
PageEvent:false, //自定义翻页动画
PageFirst:false, //翻到第一页的动作
PageLast:false, //翻到最后一页的动作
PageError:function(e){}, //翻页错误统一函数
FoundMusic:function(e){}
}, setting);
var ErrorMessage ={
PageFast:"翻页速度过快",
PageFirst:"当前已经是首页",
PageLast:"当前已经是尾页",
PageMoving:"正在翻页中,请稍后放大",
AutoTimesNull:"没有在自动播放",
ViewPageVisible:"请关闭放大页面再翻页"
};
var DefaultPageEasing = ["easeInSine","easeOutSine"];
var $self = $(this);
if(!ps.PageCount)
ps.PageCount = ps.MagJson.MagPage.length|ps.MagJson.MagIfo.PageCount;
$self.data("Jmag config",MagJson).data("MagTitle",MagJson.MagIfo.MagName).data("PageNum",ps.StarPageNum).data("PageCount",MagJson.MagIfo.PageCount);
var MagPage= MagJson.MagPage;
var $img = $(' ');
$self.data("ViewPageHtml",ps.ViewPage.find(".viewContanier").html());
var $bookimg = $("
")
if(ps.Recommended)
$.each(MagPage, function(i){
if(MagPage[i].Title != "" && MagPage[i].Title != undefined && MagPage[i].Title != null) //加载推荐栏目
ps.Recommended.html(ps.Recommended.html()+""+MagPage[i].Title+"");
});
var AutoTimes;
var events ={
SetDefaultPageSpeed:function(e,n)
{
ps.DefaultPageSpeed = n;
},
ChangeSetting:function(e,setting)
{
ps = $.fn.extend(ps,setting);
},
ChangeDefaultPageEasing:function(e,n) //变换默认翻书动画
{
switch(n){
case 0:DefaultPageEasing = ['swing','swing'];break;
case 1:DefaultPageEasing = ['easeInQuad','easeOutQuad'];break;
case 2:DefaultPageEasing = ['easeInCubic','easeOutCubic'];break;
case 3:DefaultPageEasing = ['easeInQuart','easeOutQuart'];break;
case 4:DefaultPageEasing = ['easeInQuint','easeOutQuint'];break;
case 5:DefaultPageEasing = ['easeInSine','easeOutSine'];break;
case 6:DefaultPageEasing = ['easeInExpo','easeOutExpo'];break;
case 7:DefaultPageEasing = ['easeInCirc','easeOutCirc'];break;
case 8:DefaultPageEasing = ['easeInElastic','easeOutElastic'];break;
case 9:DefaultPageEasing = ['easeInBack','easeOutBack'];break;
case 10:DefaultPageEasing = ['easeInBounce','easeOutBounce'];break;
default:DefaultPageEasing = ['swing','swing'];break;
}
},
StarJmag:function(e){
var inf = new Object();
inf.inf = "star";
this.preload(inf,[MagPage[$self.data("PageNum")],MagPage[$self.data("PageNum")+1]]);
},
CheakIsOk:function(){ //检测函数,是否可行运动
this.ComClickTime = new Date();
if(ps.ViewPage.is("div:visible"))
{
this.errMessage = ErrorMessage.ViewPageVisible;
ps.PageError(this);
return false;
}
if(ps.LeftPage.find(".contain").is(":animated") || ps.RightPage.find(".contain").is(":animated") || (this.clickDate && this.ComClickTime-this.clickDate<500) )
{
this.errMessage = ErrorMessage.PageFast;
ps.PageError(this);
return false;
}
if($self.data('style') == "PageBack" && $self.data("PageNum") <= 1)
{
this.errMessage = ErrorMessage.PageFirst;
ps.PageFirst?ps.PageFirst(this):ps.PageError(this);
events.StopAuto(AutoTimes);
return false;
}
if($self.data('style') == "PageGo" && $self.data("PageNum")>=ps.PageCount-2)
{
this.errMessage = ErrorMessage.PageLast;
ps.PageLast?ps.PageLast(this):ps.PageError(this);
events.StopAuto(AutoTimes);
return false;
}
this.clickDate = new Date();
return true;
},
PageGo:function(){
if(events.CheakIsOk())
{
if($self.data('style') == "PageGo"){
$self.trigger("JMag.preload",[[MagPage[$self.data("PageNum")+2],MagPage[$self.data("PageNum")+3]]]);
$self.data("PageNum",$self.data("PageNum")+2);
}
else if($self.data('style') == "PageBack"){
$self.trigger("JMag.preload",[[MagPage[$self.data("PageNum")-2],MagPage[$self.data("PageNum")-1]]]);
$self.data("PageNum",$self.data("PageNum")-2);
}
}
},
preload:function(e,ImageArr){
var imgAr = new Array();
ps.BeforeLoad();
for(i=0;in)
$(this).data('style','PageBack');
$(this).trigger("JMag.preload",[[$(this).data('Jmag config').MagPage[n],$(this).data('Jmag config').MagPage[n+1]]]);
$(this).data("PageNum",n);
},
StopZoom:function()
{
$(this).trigger("JMag.StopZoom");
},
ChangeSpeed:function(n)
{
$(this).trigger("JMag.SetDefaultPageSpeed",n);
},
ChangeDefaulf:function(setting){
$(this).trigger("JMag.ChangeSetting",setting);
}
};
$.each(methods, function(i) {
$.fn[i] = this;
});
})(jQuery);
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend( jQuery.easing,
{
def: 'easeOutQuad',
swing: function (x, t, b, c, d) {
//alert(jQuery.easing.default);
return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
},
easeInQuad: function (x, t, b, c, d) {
return c*(t/=d)*t + b;
},
easeOutQuad: function (x, t, b, c, d) {
return -c *(t/=d)*(t-2) + b;
},
easeInOutQuad: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t + b;
return -c/2 * ((--t)*(t-2) - 1) + b;
},
easeInCubic: function (x, t, b, c, d) {
return c*(t/=d)*t*t + b;
},
easeOutCubic: function (x, t, b, c, d) {
return c*((t=t/d-1)*t*t + 1) + b;
},
easeInOutCubic: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t + b;
return c/2*((t-=2)*t*t + 2) + b;
},
easeInQuart: function (x, t, b, c, d) {
return c*(t/=d)*t*t*t + b;
},
easeOutQuart: function (x, t, b, c, d) {
return -c * ((t=t/d-1)*t*t*t - 1) + b;
},
easeInOutQuart: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
return -c/2 * ((t-=2)*t*t*t - 2) + b;
},
easeInQuint: function (x, t, b, c, d) {
return c*(t/=d)*t*t*t*t + b;
},
easeOutQuint: function (x, t, b, c, d) {
return c*((t=t/d-1)*t*t*t*t + 1) + b;
},
easeInOutQuint: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
return c/2*((t-=2)*t*t*t*t + 2) + b;
},
easeInSine: function (x, t, b, c, d) {
return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
},
easeOutSine: function (x, t, b, c, d) {
return c * Math.sin(t/d * (Math.PI/2)) + b;
},
easeInOutSine: function (x, t, b, c, d) {
return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
},
easeInExpo: function (x, t, b, c, d) {
return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
},
easeOutExpo: function (x, t, b, c, d) {
return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
},
easeInOutExpo: function (x, t, b, c, d) {
if (t==0) return b;
if (t==d) return b+c;
if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
},
easeInCirc: function (x, t, b, c, d) {
return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
},
easeOutCirc: function (x, t, b, c, d) {
return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
},
easeInOutCirc: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
},
easeInElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
},
easeOutElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
},
easeInOutElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5);
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
},
easeInBack: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c*(t/=d)*t*((s+1)*t - s) + b;
},
easeOutBack: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
},
easeInOutBack: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
},
easeInBounce: function (x, t, b, c, d) {
return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
},
easeOutBounce: function (x, t, b, c, d) {
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
}
},
easeInOutBounce: function (x, t, b, c, d) {
if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
}
});