/*
* jquery limarquee v 4.6
*
* copyright 2013, linnik yura | li mass code | http://masscode.ru
* http://masscode.ru/index.php/k2/item/44-limarquee
* free to use
*
* last update 20.11.2014
*/
(function ($) {
var methods = {
init: function (options) {
var p = {
direction: 'left', //校泻邪蟹褘胁邪械褌 薪邪锌褉邪胁谢械薪懈械 写胁懈卸械薪懈褟 褋芯写械褉卸懈屑芯谐芯 泻芯薪褌械泄薪械褉邪 (left | right | up | down)
loop: -1, //袟邪写邪械褌, 褋泻芯谢褜泻芯 褉邪蟹 斜褍写械褌 锌褉芯泻褉褍褔懈胁邪褌褜褋褟 褋芯写械褉卸懈屑芯械. "-1" 写谢褟 斜械褋泻芯薪械褔薪芯谐芯 胁芯褋锌褉芯懈蟹胁械写械薪懈褟 写胁懈卸械薪懈褟
scrolldelay: 0, //袙械谢懈褔懈薪邪 蟹邪写械褉卸泻懈 胁 屑懈谢谢懈褋械泻褍薪写邪褏 屑械卸写褍 写胁懈卸械薪懈褟屑懈
scrollamount: 50, //小泻芯褉芯褋褌褜 写胁懈卸械薪懈褟 泻芯薪褌械薪褌邪 (px/sec)
circular: true, //袝褋谢懈 "true" - 褋褌褉芯泻邪 薪械锌褉械褉褘胁薪邪褟
drag: true, //袝褋谢懈 "true" - 胁泻谢褞褔械薪芯 锌械褉械褌邪褋泻懈胁邪薪懈械 褋褌褉芯泻懈
runshort: true, //袝褋谢懈 "true" - 泻芯褉芯褌泻邪褟 褋褌褉芯泻邪 褌芯卸械 "斜械谐邪械褌", "false" - 褋褌芯懈褌 薪邪 屑械褋褌械
hoverstop: true, //true - 褋褌褉芯泻邪 芯褋褌邪薪邪胁谢懈胁邪械褌褋褟 锌褉懈 薪邪胁械写械薪懈懈 泻褍褉褋芯褉邪 屑褘褕懈, false - 褋褌褉芯泻邪 薪械 芯褋褌邪薪邪胁谢懈胁邪械褌褋褟
inverthover: false, //false - 褋褌邪薪写邪褉褌薪芯械 锌芯胁械写械薪懈械. 袝褋谢懈 "true" - 褋褌褉芯泻邪 薪邪褔懈薪邪械褌 写胁懈卸械薪懈械 褌芯谢褜泻芯 锌褉懈 薪邪胁械写械薪懈懈 泻褍褉褋芯褉邪
xml: false //袩褍褌褜 泻 xml 褎邪泄谢褍 褋 薪褍卸薪褘屑 褌械泻褋褌芯屑
};
if (options) {
$.extend(p, options);
}
return this.each(function () {
var enterevent = 'mouseenter';
var leaveevent = 'mouseleave';
if(p.inverthover){
enterevent = 'mouseleave';
leaveevent = 'mouseenter';
}
var
loop = p.loop,
strwrap = $(this).addclass('str_wrap').data({scrollamount:p.scrollamount}),
fmove = false;
var strwrapstyle = strwrap.attr('style');
if(strwrapstyle){
var wrapstylearr = strwrapstyle.split(';');
var startheight = false;
for(var i=0; i < wrapstylearr.length; i++){
var str = $.trim(wrapstylearr[i]);
var tested = str.search(/^height/g);
if(tested != -1){
startheight = parsefloat(strwrap.css('height'));
}
}
}
var code = function () {
strwrap.off('mouseleave');
strwrap.off('mouseenter');
strwrap.off('mousemove');
strwrap.off('mousedown');
strwrap.off('mouseup');
if(!$('.str_move',strwrap).length){
strwrap.wrapinner($('
').addclass('str_move'));
}
var
strmove = $('.str_move', strwrap).addclass('str_origin'),
strmoveclone = strmove.clone().removeclass('str_origin').addclass('str_move_clone'),
time = 0;
if (!p.hoverstop) {
strwrap.addclass('nostop');
}
var circclonehor = function(){
strmoveclone.clone().css({
left:'100%',
right:'auto',
width: strmove.width()
}).appendto(strmove);
strmoveclone.css({
right: '100%',
left:'auto',
width: strmove.width()
}).appendto(strmove);
}
var circclonevert = function(){
strmoveclone.clone().css({
top: '100%',
bottom:'auto',
height: strmove.height()
}).appendto(strmove);
strmoveclone.css({
bottom: '100%',
top:'auto',
height:strmove.height()
}).appendto(strmove);
}
if (p.direction == 'left') {
strwrap.height(strmove.outerheight())
if (strmove.width() > strwrap.width()) {
var leftpos = -strmove.width();
if (p.circular) {
if (!p.xml) {
circclonehor()
leftpos = -(strmove.width() + (strmove.width() - strwrap.width()));
}
}
if (p.xml) {
strmove.css({
left:strwrap.width()
})
}
var
strmoveleft = strwrap.width(),
k1 = 0,
timefunc1 = function () {
var
fulls = math.abs(leftpos),
time = (fulls / strwrap.data('scrollamount')) * 1000;
if (parsefloat(strmove.css('left')) != 0) {
fulls = (fulls + strwrap.width());
time = (fulls - (strwrap.width() - parsefloat(strmove.css('left')))) / strwrap.data('scrollamount') * 1000;
}
return time;
},
movefuncid1 = false,
movefunc1 = function () {
if (loop != 0) {
strmove.stop(true).animate({
left: leftpos
}, timefunc1(), 'linear', function () {
$(this).css({
left: strwrap.width()
});
if (loop == -1) {
movefuncid1 = settimeout(movefunc1, p.scrolldelay);
} else {
loop--;
movefuncid1 = settimeout(movefunc1, p.scrolldelay);
}
});
}
};
strwrap.data({
moveid: movefuncid1 ,
movef : movefunc1
})
if(!p.inverthover){
movefunc1();
}
if (p.hoverstop) {
strwrap.on(enterevent, function () {
$(this).addclass('str_active');
cleartimeout(movefuncid1);
strmove.stop(true);
}).on(leaveevent, function () {
$(this).removeclass('str_active');
$(this).off('mousemove');
movefunc1();
});
if (p.drag) {
strwrap.on('mousedown', function (e) {
if(p.inverthover){
strmove.stop(true);
}
//drag
var dragleft;
var dir = 1;
var newx;
var oldx = e.clientx;
//drag
strmoveleft = strmove.position().left;
k1 = strmoveleft - (e.clientx - strwrap.offset().left);
$(this).on('mousemove', function (e) {
fmove = true;
//drag
newx = e.clientx;
if(newx > oldx){
dir = 1
}else{
dir = -1
}
oldx = newx
dragleft = k1 + (e.clientx - strwrap.offset().left);
if (!p.circular) {
if(dragleft < -strmove.width() && dir < 0){
dragleft = strwrap.width();
strmoveleft = strmove.position().left;
k1 = strmoveleft - (e.clientx - strwrap.offset().left);
}
if(dragleft > strwrap.width() && dir > 0){
dragleft = -strmove.width();
strmoveleft = strmove.position().left;
k1 = strmoveleft - (e.clientx - strwrap.offset().left);
}
}else{
if(dragleft < -strmove.width() && dir < 0){
dragleft = 0;
strmoveleft = strmove.position().left;
k1 = strmoveleft - (e.clientx - strwrap.offset().left);
}
if(dragleft > 0 && dir > 0){
dragleft = -strmove.width();
strmoveleft = strmove.position().left;
k1 = strmoveleft - (e.clientx - strwrap.offset().left);
}
}
strmove.stop(true).css({
left: dragleft
});
//drag
}).on('mouseup', function () {
$(this).off('mousemove');
if(p.inverthover){
strmove.trigger('mouseenter')
}
settimeout(function () {
fmove = false
}, 50)
});
return false;
})
.on('click', function () {
if (fmove) {
return false
}
});
} else {
strwrap.addclass('no_drag');
};
}
} else {
if (p.runshort) {
strmove.css({
left: strwrap.width()
});
var
strmoveleft = strwrap.width(),
k1 = 0,
timefunc = function () {
time = (strmove.width() + strmove.position().left) / strwrap.data('scrollamount') * 1000;
return time;
};
var movefunc = function () {
var leftpos = -strmove.width();
strmove.animate({
left: leftpos
}, timefunc(), 'linear', function () {
$(this).css({
left: strwrap.width()
});
if (loop == -1) {
settimeout(movefunc, p.scrolldelay);
} else {
loop--;
settimeout(movefunc, p.scrolldelay);
}
});
};
strwrap.data({
movef : movefunc
})
if(!p.inverthover){
movefunc();
}
if (p.hoverstop) {
strwrap.on(enterevent, function () {
$(this).addclass('str_active');
strmove.stop(true);
}).on(leaveevent, function () {
$(this).removeclass('str_active');
$(this).off('mousemove');
movefunc();
});
if (p.drag) {
strwrap.on('mousedown', function (e) {
if(p.inverthover){
strmove.stop(true);
}
//drag
var dragleft;
var dir = 1;
var newx;
var oldx = e.clientx;
//drag
strmoveleft = strmove.position().left;
k1 = strmoveleft - (e.clientx - strwrap.offset().left);
$(this).on('mousemove', function (e) {
fmove = true;
//drag
newx = e.clientx;
if(newx > oldx){
dir = 1
}else{
dir = -1
}
oldx = newx
dragleft = k1 + (e.clientx - strwrap.offset().left);
if(dragleft < -strmove.width() && dir < 0){
dragleft = strwrap.width();
strmoveleft = strmove.position().left;
k1 = strmoveleft - (e.clientx - strwrap.offset().left);
}
if(dragleft > strwrap.width() && dir > 0){
dragleft = -strmove.width();
strmoveleft = strmove.position().left;
k1 = strmoveleft - (e.clientx - strwrap.offset().left);
}
strmove.stop(true).css({
left: dragleft
});
}).on('mouseup', function () {
if(p.inverthover){
strmove.trigger('mouseenter')
}
$(this).off('mousemove');
settimeout(function () {
fmove = false
}, 50)
});
return false;
})
.on('click', function () {
if (fmove) {
return false
}
});
} else {
strwrap.addclass('no_drag');
};
}
} else {
strwrap.addclass('str_static');
}
};
};
if (p.direction == 'right') {
strwrap.height(strmove.outerheight())
strwrap.addclass('str_right');
strmove.css({
left: -strmove.width(),
right: 'auto'
})
if (strmove.width() > strwrap.width()) {
var leftpos = strwrap.width();
strmove.css({
left: 0
})
if (p.circular) {
if (!p.xml) {
circclonehor()
//袨锌褉械写械谢褟械屑 泻褉邪泄薪褞褞 褌芯褔泻褍
leftpos = strmove.width();
}
}
var
k2 = 0;
timefunc = function () {
var
fulls = strwrap.width(), //泻褉邪泄薪褟褟 褌芯褔泻邪
time = (fulls / strwrap.data('scrollamount')) * 1000; //胁褉械屑褟
if (parsefloat(strmove.css('left')) != 0) {
fulls = (strmove.width() + strwrap.width());
time = (fulls - (strmove.width() + parsefloat(strmove.css('left')))) / strwrap.data('scrollamount') * 1000;
}
return time;
};
var movefunc = function () {
if (loop != 0) {
strmove.animate({
left: leftpos
}, timefunc(), 'linear', function () {
$(this).css({
left: -strmove.width()
});
if (loop == -1) {
settimeout(movefunc, p.scrolldelay);
} else {
loop--;
settimeout(movefunc, p.scrolldelay);
};
});
};
};
strwrap.data({
movef : movefunc
})
if(!p.inverthover){
movefunc();
}
if (p.hoverstop) {
strwrap.on(enterevent, function () {
$(this).addclass('str_active');
strmove.stop(true);
}).on(leaveevent, function () {
$(this).removeclass('str_active');
$(this).off('mousemove');
movefunc();
});
if (p.drag) {
strwrap.on('mousedown', function (e) {
if(p.inverthover){
strmove.stop(true);
}
//drag
var dragleft;
var dir = 1;
var newx;
var oldx = e.clientx;
//drag
strmoveleft = strmove.position().left;
k2 = strmoveleft - (e.clientx - strwrap.offset().left);
$(this).on('mousemove', function (e) {
fmove = true;
//drag
newx = e.clientx;
if(newx > oldx){
dir = 1
}else{
dir = -1
}
oldx = newx
dragleft = k2 + (e.clientx - strwrap.offset().left);
if (!p.circular) {
if(dragleft < -strmove.width() && dir < 0){
dragleft = strwrap.width();
strmoveleft = strmove.position().left;
k2 = strmoveleft - (e.clientx - strwrap.offset().left);
}
if(dragleft > strwrap.width() && dir > 0){
dragleft = -strmove.width();
strmoveleft = strmove.position().left;
k2 = strmoveleft - (e.clientx - strwrap.offset().left);
}
}else{
if(dragleft < -strmove.width() && dir < 0){
dragleft = 0;
strmoveleft = strmove.position().left;
k2 = strmoveleft - (e.clientx - strwrap.offset().left);
}
if(dragleft > 0 && dir > 0){
dragleft = -strmove.width();
strmoveleft = strmove.position().left;
k2 = strmoveleft - (e.clientx - strwrap.offset().left);
}
}
strmove.stop(true).css({
left: dragleft
});
}).on('mouseup', function () {
if(p.inverthover){
strmove.trigger('mouseenter')
}
$(this).off('mousemove');
settimeout(function () {
fmove = false
}, 50)
});
return false;
})
.on('click', function () {
if (fmove) {
return false
}
});
} else {
strwrap.addclass('no_drag');
};
}
} else {
if (p.runshort) {
var k2 = 0;
var timefunc = function () {
time = (strwrap.width() - strmove.position().left) / strwrap.data('scrollamount') * 1000;
return time;
};
var movefunc = function () {
var leftpos = strwrap.width();
strmove.animate({
left: leftpos
}, timefunc(), 'linear', function () {
$(this).css({
left: -strmove.width()
});
if (loop == -1) {
settimeout(movefunc, p.scrolldelay);
} else {
loop--;
settimeout(movefunc, p.scrolldelay);
};
});
};
strwrap.data({
movef : movefunc
})
if(!p.inverthover){
movefunc();
}
if (p.hoverstop) {
strwrap.on(enterevent, function () {
$(this).addclass('str_active');
strmove.stop(true);
}).on(leaveevent, function () {
$(this).removeclass('str_active');
$(this).off('mousemove');
movefunc();
});
if (p.drag) {
strwrap.on('mousedown', function (e) {
if(p.inverthover){
strmove.stop(true);
}
//drag
var dragleft;
var dir = 1;
var newx;
var oldx = e.clientx;
//drag
strmoveleft = strmove.position().left;
k2 = strmoveleft - (e.clientx - strwrap.offset().left);
$(this).on('mousemove', function (e) {
fmove = true;
//drag
newx = e.clientx;
if(newx > oldx){
dir = 1
}else{
dir = -1
}
oldx = newx
dragleft = k2 + (e.clientx - strwrap.offset().left);
if(dragleft < -strmove.width() && dir < 0){
dragleft = strwrap.width();
strmoveleft = strmove.position().left;
k2 = strmoveleft - (e.clientx - strwrap.offset().left);
}
if(dragleft > strwrap.width() && dir > 0){
dragleft = -strmove.width();
strmoveleft = strmove.position().left;
k2 = strmoveleft - (e.clientx - strwrap.offset().left);
}
strmove.stop(true).css({
left:dragleft
});
}).on('mouseup', function () {
if(p.inverthover){
strmove.trigger('mouseenter')
}
$(this).off('mousemove');
settimeout(function () {
fmove = false
}, 50)
});
return false;
})
.on('click', function () {
if (fmove) {
return false
}
});
} else {
strwrap.addclass('no_drag');
};
}
} else {
strwrap.addclass('str_static');
}
};
};
if (p.direction == 'up') {
strwrap.addclass('str_vertical');
if (strmove.height() > strwrap.height()) {
var toppos = -strmove.height();
if (p.circular) {
if (!p.xml) {
circclonevert();
toppos = -(strmove.height() + (strmove.height() - strwrap.height()));
}
}
if (p.xml) {
strmove.css({
top:strwrap.height()
})
}
var
k2 = 0;
timefunc = function () {
var
fulls = math.abs(toppos),
time = (fulls / strwrap.data('scrollamount')) * 1000;
if (parsefloat(strmove.css('top')) != 0) {
fulls = (fulls + strwrap.height());
time = (fulls - (strwrap.height() - parsefloat(strmove.css('top')))) / strwrap.data('scrollamount') * 1000;
}
return time;
};
var movefunc = function () {
if (loop != 0) {
strmove.animate({
top: toppos
}, timefunc(), 'linear', function () {
$(this).css({
top: strwrap.height()
});
if (loop == -1) {
settimeout(movefunc, p.scrolldelay);
} else {
loop--;
settimeout(movefunc, p.scrolldelay);
};
});
};
};
strwrap.data({
movef : movefunc
})
if(!p.inverthover){
movefunc();
}
if (p.hoverstop) {
strwrap.on(enterevent, function () {
$(this).addclass('str_active');
strmove.stop(true);
}).on(leaveevent, function () {
$(this).removeclass('str_active');
$(this).off('mousemove');
movefunc();
});
if (p.drag) {
strwrap.on('mousedown', function (e) {
if(p.inverthover){
strmove.stop(true);
}
//drag
var dragtop;
var dir = 1;
var newy;
var oldy = e.clienty;
//drag
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
$(this).on('mousemove', function (e) {
fmove = true;
//drag
newy = e.clienty;
if(newy > oldy){
dir = 1
}else{
if(newy < oldy){
dir = -1
}
}
oldy = newy
dragtop = k2 + e.clienty - strwrap.offset().top;
if (!p.circular){
if(dragtop < -strmove.height() && dir < 0){
dragtop = strwrap.height();
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
}
if(dragtop > strwrap.height() && dir > 0){
dragtop = -strmove.height();
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
}
}else{
if(dragtop < -strmove.height() && dir < 0){
dragtop = 0;
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
}
if(dragtop > 0 && dir > 0){
dragtop = -strmove.height();
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
}
}
strmove.stop(true).css({
top: dragtop
});
//drag
}).on('mouseup', function () {
if(p.inverthover){
strmove.trigger('mouseenter')
}
$(this).off('mousemove');
settimeout(function () {
fmove = false
}, 50)
});
return false;
})
.on('click', function () {
if (fmove) {
return false
}
});
} else {
strwrap.addclass('no_drag');
};
}
} else {
if (p.runshort) {
strmove.css({
top: strwrap.height()
});
var k2 = 0;
var timefunc = function () {
time = (strmove.height() + strmove.position().top) / strwrap.data('scrollamount') * 1000;
return time;
};
var movefunc = function () {
var toppos = -strmove.height();
strmove.animate({
top: toppos
}, timefunc(), 'linear', function () {
$(this).css({
top: strwrap.height()
});
if (loop == -1) {
settimeout(movefunc, p.scrolldelay);
} else {
loop--;
settimeout(movefunc, p.scrolldelay);
};
});
};
strwrap.data({
movef : movefunc
})
if(!p.inverthover){
movefunc();
}
if (p.hoverstop) {
strwrap.on(enterevent, function () {
$(this).addclass('str_active');
strmove.stop(true);
}).on(leaveevent, function () {
$(this).removeclass('str_active');
$(this).off('mousemove');
movefunc();
});
if (p.drag) {
strwrap.on('mousedown', function (e) {
if(p.inverthover){
strmove.stop(true);
}
//drag
var dragtop;
var dir = 1;
var newy;
var oldy = e.clienty;
//drag
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
$(this).on('mousemove', function (e) {
fmove = true;
//drag
newy = e.clienty;
if(newy > oldy){
dir = 1
}else{
if(newy < oldy){
dir = -1
}
}
oldy = newy
dragtop = k2 + e.clienty - strwrap.offset().top;
if(dragtop < -strmove.height() && dir < 0){
dragtop = strwrap.height();
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
}
if(dragtop > strwrap.height() && dir > 0){
dragtop = -strmove.height();
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
}
//*drag
strmove.stop(true).css({
top: dragtop
});
}).on('mouseup', function () {
if(p.inverthover){
strmove.trigger('mouseenter')
}
$(this).off('mousemove');
settimeout(function () {
fmove = false
}, 50)
});
return false;
})
.on('click', function () {
if (fmove) {
return false
}
});
} else {
strwrap.addclass('no_drag');
};
}
} else {
strwrap.addclass('str_static');
}
};
};
if (p.direction == 'down') {
strwrap.addclass('str_vertical').addclass('str_down');
strmove.css({
top: -strmove.height(),
bottom: 'auto'
})
if (strmove.height() > strwrap.height()) {
var toppos = strwrap.height();
if (p.circular) {
if (!p.xml) {
circclonevert();
toppos = strmove.height();
}
}
if (p.xml) {
strmove.css({
top:-strmove.height()
})
}
var
k2 = 0;
timefunc = function () {
var
fulls = strwrap.height(), //泻褉邪泄薪褟褟 褌芯褔泻邪
time = (fulls / strwrap.data('scrollamount')) * 1000; //胁褉械屑褟
if (parsefloat(strmove.css('top')) != 0) {
fulls = (strmove.height() + strwrap.height());
time = (fulls - (strmove.height() + parsefloat(strmove.css('top')))) / strwrap.data('scrollamount') * 1000;
}
return time;
};
var movefunc = function () {
if (loop != 0) {
strmove.animate({
top: toppos
}, timefunc(), 'linear', function () {
$(this).css({
top: -strmove.height()
});
if (loop == -1) {
settimeout(movefunc, p.scrolldelay);
} else {
loop--;
settimeout(movefunc, p.scrolldelay);
};
});
};
};
strwrap.data({
movef : movefunc
})
if(!p.inverthover){
movefunc();
}
if (p.hoverstop) {
strwrap.on(enterevent, function () {
$(this).addclass('str_active');
strmove.stop(true);
}).on(leaveevent, function () {
$(this).removeclass('str_active');
$(this).off('mousemove');
movefunc();
});
if (p.drag) {
strwrap.on('mousedown', function (e) {
if(p.inverthover){
strmove.stop(true);
}
//drag
var dragtop;
var dir = 1;
var newy;
var oldy = e.clienty;
//drag
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
$(this).on('mousemove', function (e) {
fmove = true;
//drag
newy = e.clienty;
if(newy > oldy){
dir = 1
}else{
if(newy < oldy){
dir = -1
}
}
oldy = newy
dragtop = k2 + e.clienty - strwrap.offset().top;
if (!p.circular){
if(dragtop < -strmove.height() && dir < 0){
dragtop = strwrap.height();
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
}
if(dragtop > strwrap.height() && dir > 0){
dragtop = -strmove.height();
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
}
}else{
if(dragtop < -strmove.height() && dir < 0){
dragtop = 0;
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
}
if(dragtop > 0 && dir > 0){
dragtop = -strmove.height();
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
}
}
strmove.stop(true).css({
top: dragtop
});
//drag
}).on('mouseup', function () {
if(p.inverthover){
strmove.trigger('mouseenter')
}
$(this).off('mousemove');
settimeout(function () {
fmove = false
}, 50)
});
return false;
})
.on('click', function () {
if (fmove) {
return false
}
});
} else {
strwrap.addclass('no_drag');
};
}
} else {
if (p.runshort) {
var k2 = 0;
var timefunc = function () {
time = (strwrap.height() - strmove.position().top) / strwrap.data('scrollamount') * 1000;
return time;
};
var movefunc = function () {
var toppos = strwrap.height();
strmove.animate({
top: toppos
}, timefunc(), 'linear', function () {
$(this).css({
top: -strmove.height()
});
if (loop == -1) {
settimeout(movefunc, p.scrolldelay);
} else {
loop--;
settimeout(movefunc, p.scrolldelay);
};
});
};
strwrap.data({
movef : movefunc
})
if(!p.inverthover){
movefunc();
}
if (p.hoverstop) {
strwrap.on(enterevent, function () {
$(this).addclass('str_active');
strmove.stop(true);
}).on(leaveevent, function () {
$(this).removeclass('str_active');
$(this).off('mousemove');
movefunc();
});
if (p.drag) {
strwrap.on('mousedown', function (e) {
if(p.inverthover){
strmove.stop(true);
}
//drag
var dragtop;
var dir = 1;
var newy;
var oldy = e.clienty;
//drag
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
$(this).on('mousemove', function (e) {
fmove = true;
//drag
newy = e.clienty;
if(newy > oldy){
dir = 1
}else{
if(newy < oldy){
dir = -1
}
}
oldy = newy
dragtop = k2 + e.clienty - strwrap.offset().top;
if(dragtop < -strmove.height() && dir < 0){
dragtop = strwrap.height();
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
}
if(dragtop > strwrap.height() && dir > 0){
dragtop = -strmove.height();
strmovetop = strmove.position().top;
k2 = strmovetop - (e.clienty - strwrap.offset().top);
}
//*drag
strmove.stop(true).css({
top: dragtop
});
}).on('mouseup', function () {
if(p.inverthover){
strmove.trigger('mouseenter')
}
$(this).off('mousemove');
settimeout(function () {
fmove = false
}, 50)
})
return false;
})
.on('click', function () {
if (fmove) {
return false
}
});
} else {
strwrap.addclass('no_drag');
};
}
} else {
strwrap.addclass('str_static');
}
};
};
}
if (p.xml) {
$.ajax({
url: p.xml,
datatype: "xml",
success: function (xml) {
var xmltextel = $(xml).find('text');
var xmltextlength = xmltextel.length;
for(var i = 0; i < xmltextlength; i++){
var xmlelactive = xmltextel.eq(i);
var xmlelcontent = xmlelactive.text();
var xmlitemel = $('').text(xmlelcontent).appendto(strwrap);
if(p.direction == 'left' || p.direction == 'right'){
xmlitemel.css({display:'inline-block',textalign:'right'});
if(i > 0){
xmlitemel.css({width:strwrap.width()+xmlitemel.width()});
}
}
if(p.direction == 'down' || p.direction == 'up'){
xmlitemel.css({display:'block',textalign:'left'});
if(i > 0){
xmlitemel.css({paddingtop:strwrap.height()});
}
}
}
code();
}
});
} else {
code();
}
strwrap.data({
ini:code,
startheight: startheight
})
});
},
update: function () {
var el = $(this);
var str_origin = $('.str_origin',el);
var str_move_clone = $('.str_move_clone',el);
str_origin.stop(true);
str_move_clone.remove();
el.data('ini')();
},
destroy: function () {
var el = $(this);
var elmove = $('.str_move',el);
var startheight = el.data('startheight');
$('.str_move_clone',el).remove();
el.off('mouseenter');
el.off('mousedown');
el.off('mouseup');
el.off('mouseleave');
el.off('mousemove');
el.removeclass('nostop').removeclass('str_vertical').removeclass('str_active').removeclass('no_drag').removeclass('str_static').removeclass('str_right').removeclass('str_down');
var elstyle = el.attr('style');
if(elstyle){
var stylearr = elstyle.split(';');
for(var i=0; i < stylearr.length; i++){
var str = $.trim(stylearr[i]);
var tested = str.search(/^height/g);
if(tested != -1){
stylearr[i] = '';
}
}
var newarr = stylearr.join(';');
var newstyle = newarr.replace(/;+/g,';')
if(newstyle == ';'){
el.removeattr('style');
}else{
el.attr('style',newstyle);
}
if(startheight){
el.css({height:startheight})
}
}
elmove.stop(true);
if(elmove.length){
var context = elmove.html();
elmove.remove();
el.html(context);
}
},
pause: function(){
var el = $(this);
var elmove = $('.str_move',el);
elmove.stop(true);
},
play: function(){
var el = $(this);
$(this).off('mousemove');
el.data('movef')();
}
};
$.fn.limarquee = function (method) {
if (methods[method]) {
return methods[method].apply(this, array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('袦械褌芯写 ' + method + ' 胁 jquery.limarquee 薪械 褋褍褖械褋褌胁褍械褌');
}
};
})(jquery);