Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sb_karaoke_cocos
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
sb_karaoke_cocos
Commits
3942b415
Commit
3942b415
authored
Jan 08, 2021
by
Li MingZhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 底部item 宽度适配
parent
d896137d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
10 deletions
+54
-10
bgBottom.js
play/assets/ljx_karaoke/prefab/bgBottom.js
+54
-10
No files found.
play/assets/ljx_karaoke/prefab/bgBottom.js
View file @
3942b415
...
...
@@ -22,6 +22,7 @@ cc.Class({
_maxPage
:
null
,
_lineMaxCount
:
null
,
_disW
:
null
,
_maxW
:
null
,
onLoad
()
{
this
.
_canTouch
=
true
;
this
.
_isTop
=
false
;
...
...
@@ -35,8 +36,8 @@ cc.Class({
this
.
_maxPage
=
0
;
this
.
_disW
=
5
;
const
maxW
=
1280
-
90
;
this
.
_lineMaxCount
=
Math
.
floor
(
maxW
/
(
this
.
_disW
+
this
.
_itemLen
));
this
.
_
maxW
=
1280
-
90
;
this
.
_lineMaxCount
=
Math
.
floor
(
this
.
_
maxW
/
(
this
.
_disW
+
this
.
_itemLen
));
},
...
...
@@ -112,7 +113,7 @@ cc.Class({
return
;
}
if
(
this
.
_pageIndex
>=
this
.
_maxPage
)
{
if
(
this
.
_pageIndex
>=
this
.
_maxPage
-
1
)
{
return
;
}
this
.
_pageIndex
++
;
...
...
@@ -142,7 +143,7 @@ cc.Class({
this
.
_pageUpBtn
.
opacity
=
255
;
}
if
(
this
.
_pageIndex
==
this
.
_maxPage
)
{
if
(
this
.
_pageIndex
==
this
.
_maxPage
-
1
)
{
this
.
_pageDownBtn
.
opacity
=
100
;
}
else
{
this
.
_pageDownBtn
.
opacity
=
255
;
...
...
@@ -185,12 +186,35 @@ cc.Class({
return
;
}
this
.
_dataArr
=
dataArr
;
this
.
_maxPage
=
Math
.
ceil
(
dataArr
.
length
/
this
.
_lineMaxCount
)
-
1
;
// this._maxPage = Math.ceil(dataArr.length / this._lineMaxCount) - 1;
this
.
_initPageArr
();
this
.
_pageIndex
=
0
;
this
.
_refreshPage
();
},
_pageArr
:
null
,
_initPageArr
()
{
let
tmpArr
=
[];
this
.
_pageArr
=
[
tmpArr
];
let
curLen
=
this
.
_disW
;
for
(
let
i
=
0
;
i
<
this
.
_dataArr
.
length
;
i
++
)
{
const
item
=
this
.
_addOneItem
(
this
.
_dataArr
[
i
]);
curLen
+=
item
.
width
+
this
.
_disW
;
if
(
curLen
>
this
.
_maxW
)
{
tmpArr
=
[
item
];
this
.
_pageArr
.
push
(
tmpArr
);
}
else
{
tmpArr
.
push
(
item
);
}
}
this
.
_maxPage
=
this
.
_pageArr
.
length
;
console
.
log
(
'
this._maxPage:
'
,
this
.
_maxPage
);
},
_itemLen
:
null
,
_addOneItem
(
data
)
{
...
...
@@ -207,6 +231,7 @@ cc.Class({
this
.
_addItemLabel
(
item
,
data
.
text
);
this
.
_addItemAudio
(
item
,
data
.
audio_url
);
item
.
data
=
data
;
return
item
;
},
...
...
@@ -254,6 +279,10 @@ cc.Class({
}
label
.
font
=
this
.
_labelFont
;
label
.
_forceUpdateRenderData
(
true
)
if
(
labelNode
.
width
>
this
.
_itemLen
)
{
item
.
width
=
labelNode
.
width
;
}
},
...
...
@@ -286,20 +315,35 @@ cc.Class({
const
disW
=
this
.
_disW
;
const
startIndex
=
this
.
_pageIndex
*
this
.
_lineMaxCount
;
const
showArr
=
dataArr
.
slice
(
startIndex
,
startIndex
+
this
.
_lineMaxCount
);
// const showArr = dataArr.slice(startIndex, startIndex + this._lineMaxCount);
const
showArr
=
this
.
_pageArr
[
this
.
_pageIndex
];
let
baseX
=
this
.
_getCurPageBaseX
();
const
baseX
=
-
(
disW
+
this
.
_itemLen
)
*
(
showArr
.
length
-
1
)
/
2
;
// const baseX = -(disW + this._itemLen) * (showArr.length - 1) / 2;
const
baseY
=
-
25
;
showArr
.
forEach
((
data
,
i
)
=>
{
const
item
=
this
.
_addOneItem
(
data
);
showArr
.
forEach
((
el
,
i
)
=>
{
const
item
=
this
.
_addOneItem
(
el
.
data
);
this
.
_itemLayer
.
addChild
(
item
);
item
.
x
=
baseX
+
(
disW
+
this
.
_itemLen
)
*
i
;
item
.
x
=
baseX
+
(
disW
+
item
.
width
)
/
2
item
.
y
=
baseY
;
baseX
=
item
.
x
+
(
disW
+
item
.
width
)
/
2
;
});
this
.
_setPageBtnState
();
},
_getCurPageBaseX
()
{
const
arr
=
this
.
_pageArr
[
this
.
_pageIndex
];
console
.
log
(
'
arr:
'
,
arr
);
let
curLen
=
this
.
_disW
;
for
(
let
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
curLen
+=
(
arr
[
i
].
width
+
this
.
_disW
)
}
return
-
curLen
/
2
;
},
// update (dt) {},
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment