带 ngFor 的离子 4 水平滚动
Ionic 4 horizontal scroll with ngFor
我很茫然。我可以让水平滚动正常工作 html 和 css 但是当我引入 ngFor 时,它拒绝产生相同的效果..有没有人有这方面的经验,或者知道如何解决这个问题?
我的简单代码不起作用:
此示例生成一个垂直列表:
<div class="container" *ngFor="let item of items | async">
<div class="scroll" scrollX="true">
<span>{{item.ProjectEvent}}</span>
</div>
</div>
而这个会产生一个水平滚动的宽容器
<div class="container" >
<div class="scroll" scrollX="true">
<span>item1</span>
<span>item2</span>
<span>item3</span>
<span>item4</span>
<span>item5</span>
<span>item6</span>
<span>item7</span>
<span>item8</span>
<span>item9</span>
</div>
</div>
两者相同 css:
.container {
width: 100px;
background-color: green;
overflow: hidden;
white-space: nowrap;
::-webkit-scrollbar {
display: none;
}
.scroll {
overflow: auto;
}
}
Spock 先生给我解释一下!
提前感谢您的帮助!
良好措施的依赖性:
"dependencies": {
"@angular/common": "^7.1.4",
"@angular/core": "^7.1.4",
"@angular/fire": "^5.1.1",
"@angular/forms": "^7.1.4",
"@angular/http": "^7.1.4",
"@angular/platform-browser": "^7.1.4",
"@angular/platform-browser-dynamic": "^7.1.4",
"@angular/router": "^7.1.4",
"@ionic-native/core": "5.0.0-beta.21",
"@ionic-native/splash-screen": "5.0.0-beta.21",
"@ionic-native/status-bar": "5.0.0-beta.21",
"@ionic/angular": "4.0.0",
"@ionic/pro": "2.0.4",
"core-js": "^2.5.4",
"firebase": "^5.8.0",
"ngx-navigation-with-data": "^1.0.2",
"rxjs": "~6.3.3",
"zone.js": "~0.8.26"
},
尝试对需要复制的实际元素使用指令:
<div class="container">
<div class="scroll" scrollX="true">
<span *ngFor="let item of items | async">{{item.ProjectEvent}}</span>
</div>
</div>
使用 flexbox:
div[scrollx=true] {
display: flex;
flex-wrap: nowrap;
overflow-x: auto;
&::-webkit-scrollbar {
display: none;
}
.scroll-item {
flex: 0 0 auto;
}
}
https://codeburst.io/how-to-create-horizontal-scrolling-containers-d8069651e9c6
或许可以试试
<ion-segment scrollable="true">
<ion-segment-button value="friends">
<ion-label>Friends</ion-label>
</ion-segment-button>
</ion-segment>
我很茫然。我可以让水平滚动正常工作 html 和 css 但是当我引入 ngFor 时,它拒绝产生相同的效果..有没有人有这方面的经验,或者知道如何解决这个问题?
我的简单代码不起作用:
此示例生成一个垂直列表:
<div class="container" *ngFor="let item of items | async">
<div class="scroll" scrollX="true">
<span>{{item.ProjectEvent}}</span>
</div>
</div>
而这个会产生一个水平滚动的宽容器
<div class="container" >
<div class="scroll" scrollX="true">
<span>item1</span>
<span>item2</span>
<span>item3</span>
<span>item4</span>
<span>item5</span>
<span>item6</span>
<span>item7</span>
<span>item8</span>
<span>item9</span>
</div>
</div>
两者相同 css:
.container {
width: 100px;
background-color: green;
overflow: hidden;
white-space: nowrap;
::-webkit-scrollbar {
display: none;
}
.scroll {
overflow: auto;
}
}
Spock 先生给我解释一下!
提前感谢您的帮助!
良好措施的依赖性:
"dependencies": {
"@angular/common": "^7.1.4",
"@angular/core": "^7.1.4",
"@angular/fire": "^5.1.1",
"@angular/forms": "^7.1.4",
"@angular/http": "^7.1.4",
"@angular/platform-browser": "^7.1.4",
"@angular/platform-browser-dynamic": "^7.1.4",
"@angular/router": "^7.1.4",
"@ionic-native/core": "5.0.0-beta.21",
"@ionic-native/splash-screen": "5.0.0-beta.21",
"@ionic-native/status-bar": "5.0.0-beta.21",
"@ionic/angular": "4.0.0",
"@ionic/pro": "2.0.4",
"core-js": "^2.5.4",
"firebase": "^5.8.0",
"ngx-navigation-with-data": "^1.0.2",
"rxjs": "~6.3.3",
"zone.js": "~0.8.26"
},
尝试对需要复制的实际元素使用指令:
<div class="container">
<div class="scroll" scrollX="true">
<span *ngFor="let item of items | async">{{item.ProjectEvent}}</span>
</div>
</div>
使用 flexbox:
div[scrollx=true] {
display: flex;
flex-wrap: nowrap;
overflow-x: auto;
&::-webkit-scrollbar {
display: none;
}
.scroll-item {
flex: 0 0 auto;
}
}
https://codeburst.io/how-to-create-horizontal-scrolling-containers-d8069651e9c6
或许可以试试
<ion-segment scrollable="true">
<ion-segment-button value="friends">
<ion-label>Friends</ion-label>
</ion-segment-button>
</ion-segment>