mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-05-22 16:39:35 +08:00
添加ScrollView组件demo
This commit is contained in:
55
ScrollViewDemo/assets/Script/HelloWorld.js
Normal file
55
ScrollViewDemo/assets/Script/HelloWorld.js
Normal file
@@ -0,0 +1,55 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
horizontal: cc.ScrollView,
|
||||
vertical: cc.ScrollView,
|
||||
grid: cc.ScrollView,
|
||||
item: cc.Node,
|
||||
},
|
||||
|
||||
// use this for initialization
|
||||
onLoad: function () {
|
||||
// this.label.string = this.text;
|
||||
this.horizontal.node.active = true;
|
||||
this.vertical.node.active = false;
|
||||
this.grid.node.active = false;
|
||||
},
|
||||
|
||||
onBtnClicked(event, customData) {
|
||||
console.log('customData=', customData);
|
||||
this.horizontal.node.active = false;
|
||||
this.vertical.node.active = false;
|
||||
this.grid.node.active = false;
|
||||
var node = this.node.getChildByName(customData);
|
||||
switch (node.name) {
|
||||
case 'horizontal': {
|
||||
this.horizontal.node.active = true;
|
||||
this.onAddItem(this.horizontal, this.item);
|
||||
break;
|
||||
}
|
||||
case 'vertical': {
|
||||
this.vertical.node.active = true;
|
||||
this.onAddItem(this.vertical, this.item);
|
||||
break;
|
||||
}
|
||||
case 'grid': {
|
||||
this.grid.node.active = true;
|
||||
this.onAddItem(this.grid, this.item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onAddItem(scrollView, item) {
|
||||
console.log(scrollView.node);
|
||||
var contentNode = scrollView.node.getChildByName('view').getChildByName('content');
|
||||
var child = cc.instantiate(item);
|
||||
contentNode.addChild(child);
|
||||
},
|
||||
|
||||
// called every frame
|
||||
update: function (dt) {
|
||||
|
||||
},
|
||||
});
|
||||
9
ScrollViewDemo/assets/Script/HelloWorld.js.meta
Normal file
9
ScrollViewDemo/assets/Script/HelloWorld.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "280c3aec-6492-4a9d-9f51-a9b00b570b4a",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
Reference in New Issue
Block a user