$scope
.data = {comment:''};
$scope
.danmuCount = 5;
$scope
.danmus = ['1545466666还是','9777777','哈哈哈哈哈','对企业读完后环球网好齐齐哈','42115我我我5','556噢噢噢噢45','54哦','54545646','666但近段时间66','56565','454465465565', '1545466666还是','9777777','哈哈哈哈哈','对企业读完后环球网好齐齐哈','42115我我我5','556噢噢噢噢45','54哦','54545646','666但近段时间66','56565','454465465565'];
$scope
.createDanmuContent =
function
() {
var
height = 1 /
$scope
.danmuCount * 100 + '%';
for
(
var
i = 0; i <
$scope
.danmuCount; i++) {
var
item = '<p style=
"width: 100%; height: '+height+'"
></p>';
$('.mask').append(item);
}
$scope
.createDanmu ();
};
$scope
.createDanmu =
function
() {
var
maxCount = 0;
if
(
$scope
.danmus.length >
$scope
.danmuCount) {
maxCount =
$scope
.danmuCount;
}
else
{
maxCount =
$scope
.danmus.length;
}
var
_left = window.screen.width;
for
(
var
i = 0; i < maxCount; i++) {
var
_lable = $(
"<p style='margin: 0;position: absolute;opacity:1;display:table;left: "
+_left + 'px'+';color:'+
$scope
.getRandomColor()+
"'>"
+
$scope
.danmus[i]+
"</p>"
);
$(
".mask p"
).each(
function
() {
if
(
$scope
.checkDanmu($(this))) {
$(this).append(_lable);
$scope
.moveArray(i);
i--;
return
false;
}
});
}
$scope
.init_barrage();
};
$scope
.moveArray =
function
(i) {
var
temp =
$scope
.danmus[i];
$scope
.danmus.splice(i,1);
$scope
.danmus.push(temp);
}
$scope
.checkDanmu =
function
(el) {
return
el.find('p').length == 0 ? true : false;
};
$scope
.getRandomColor =
function
() {
return
'#' + (
function
(h){
return
new
Array(7 - h.length).join(
"0"
) + h
})((Math.random() * 0x1000000 << 0).toString(16))
};
$scope
.init_barrage =
function
() {
$(
".mask p p"
).show().each(
function
() {
var
_moveLeft = window.screen.width+$(this).width();
var
time = 100000 / $(this).width() + 5000;
$scope
.addCssAnimate($(this),_moveLeft,time);
});
};
$scope
.addCssAnimate =
function
(el,_moveLeft,time) {
el.css({
'transform':'translateX('+-_moveLeft+'px)',
'transition':'all '+time+'ms'+ ' linear',
'-webkit-transform':'translateX('+-_moveLeft+'px)',
'-webkit-transition':'all '+time+'ms'+ ' linear',
'-moz-transform':'translateX('+-_moveLeft+'px)',
'-moz-transition':'all '+time+'ms'+ ' linear',
'-ms-transform':'translateX('+-_moveLeft+'px)',
'-ms-transition':'all '+time+'ms'+ ' linear'
});
$timeout
(
function
() {
if
(
$scope
.danmus.length > 0) {
el.css({
'transform':'translateX(0px)',
'transition':'all 0ms linear',
'-webkit-transform':'translateX(0px)',
'-webkit-transition':'all 0ms linear',
'-moz-transform':'translateX(0px)',
'-moz-transition':'all 0ms linear',
'-ms-transform':'translateX(0px)',
'-ms-transition':'all 0ms linear'
});
$scope
.resetAnimate(el);
}
else
{
el.remove();
}
},time);
};
$scope
.resetAnimate =
function
(el) {
el.html(
$scope
.danmus[0]);
$scope
.moveArray(0);
var
_moveLeft = el.width() + screen.width;
var
time = 100000 / el.width() + 5000;
$scope
.addCssAnimate(el,_moveLeft,time);
};
$scope
.addDanmu =
function
() {
var
text =
$scope
.data.comment;
if
(text ==
""
){
return
;
}
$scope
.danmus.unshift(text);
};
$scope
.createDanmuContent();