我正在制作一个电子商务应用。在我的主页上,我按类别显示我的产品。我正在使用离子段和离子滑板,以便用户可以一次滚动和选择两者。当我有三个类别时,它很好,所有都在家里展示,但当我增加类别时,其他类别都在屏幕后面。类别产品显示正常但类别名称在内部且不可见。我想在屏幕上滚动同时显示的类别名称和产品。这就是我想让屏幕上的活动片段可见,当片段在屏幕外时。提前谢谢:-)
<ion-content>
<ion-segment color="dark" [(ngModel)]="tabs" style="width:640px;">
<ion-segment-button *ngFor="let i of productcategory" (click)="selectTab(i)" value="{{i.inc}}" >{{i.category_name}}</ion-segment-button>
<div id="slide" class="slide"></div>
</ion-segment>
<ion-slides #pageSlider (ionSlideWillChange)="changeWillSlide($event)">
<ion-slide *ngFor="let i of productcategory">
<ion-list>
<div *ngFor="let pr of products; let i=index" text-wrap class="swipe-tabs">
<div class="swipe-tabs-1">
<img src="http://example.com/{{pr.tbl_product_image}}" />
<button ion-button (click)="removefromcart(pr,i)">-</button>
<button ion-button color="light" *ngIf="check">{{quan[i]}}</button>
<button ion-button color="light" *ngIf="!check">0</button>
<button ion-button (click)="addToCart(pr,i)">+</button>
</div>
<div class="swipe-tabs-2">
<h2>{{pr.tbl_product_name}} </h2>
<ion-list radio-group >
<ion-item *ngFor="let p of pr.pricevariant; let j=index;">
<ion-label>{{p.weight}} <span class="colr-red">₹ {{p.dprice}}</span></ion-label>
<ion-radio [value]="p.weight" (ionSelect)="getdata(pr,p,i,j)" ></ion-radio>
</ion-item>
</ion-list>
</div>
<div class="border-hr"></div>
</div>
</ion-list>
</ion-slide>
</ion-slides>
答案 0 :(得分:0)
我是通过在标题中制作内容并在滑动期间调整某些事件来实现的: -
<ion-header>
<ion-content #scroll scrollX="true" scrollY="true" style="height: 50px;">
<ion-segment class="SwipedTabs-tabs">
<ion-segment-button *ngFor='let tab of tabs ; let i = index ' value="IngoreMe" (click)="selectTab(i)" [ngClass]='{ "SwipedTabs-activeTab" : ( this.SwipedTabsSlider && ( this.SwipedTabsSlider.getActiveIndex() === i || ( tabs.length -1 === i&& this.SwipedTabsSlider.isEnd()))) }'
[ngStyle]="{'width.px': (this.tabElementWidth_px)}">
{{tab}}
</ion-segment-button>
</ion-segment>
<!-- here is our dynamic line "indicator"-->
<div id='indicator' class="SwipedTabs-indicatorSegment" [ngStyle]="{'width.px': (this.tabElementWidth_px)}"></div>
</ion-content>
<ion-slides #SwipedTabsSlider (ionSlideDrag)="animateIndicator($event)" (ionSlideWillChange)="updateIndicatorPosition()" (ionSlideDidChange)="updateIndicatorPosition()" (pan)="updateIndicatorPosition()" [pager]="false">
在打字稿中: -
this.tabs=["SNACKS","SWEETS","NAMKKEN","BAKERY","MISC","ETC"];
selectTab(index) {
this.SwipedTabsIndicator.style.webkitTransform = 'translate3d('+(100*index)+'%,0,0)';
this.scroll.scrollTo(index*this.tabElementWidth_px,0,500);
this.SwipedTabsSlider.slideTo(index, 500);}
updateIndicatorPosition() {
this.scroll.scrollTo(this.SwipedTabsSlider.getActiveIndex()*this.tabElementWidth_px,0,200);
// this condition is to avoid passing to incorrect index
if( this.SwipedTabsSlider.length()> this.SwipedTabsSlider.getActiveIndex())
{
this.SwipedTabsIndicator.style.webkitTransform = 'translate3d('+(this.SwipedTabsSlider.getActiveIndex() * 100)+'%,0,0)';
}
this.j=this.SwipedTabsSlider.getActiveIndex();
}
在css中:
page-home {
.segment-ios .segment-button {
overflow: inherit !important;
color: #fff !important;
padding: 0 10px;
border-right: 1px solid white !important;
width: auto !important;
}
.SwipedTabs-indicatorSegment {
-webkit-transition: 0.3s all;
-moz-transition: 0.3s all;
-o-transition: 0.3s all;
transition: 0.3s all;
transform-origin: top 0 left 0;
height: 1px;
position: relative;
top: -2px;
background-color: white !important;
}
.SwipedTabs-tabs ion-segment-button {
border: none !important;
color: black!important;
background-color: blue!important;
display: -webkit-inline-box;
}
.SwipedTabs-tabs ion-segment-button.SwipedTabs-activeTab {
color: white !important;
font-size: 17px;
font-weight: bold;
}
.SwipedTabs-tabs {
width: fit-content !important;
border-bottom: solid 1px #e6e6e6 !important;
}
.scroll-content {
display: flex;
left: -3px;
right: 0;
top: 3px;
}
.swiper-container {
overflow-y: scroll !important;
}
scroll-content {
margin-top: 35px;
margin-bottom: -297px;
}
.SwipedTabs-tabs ion-segment-button {
color: #fff !important;
padding: 0 10px;
}
}
答案 1 :(得分:0)
您可以使用以下代码实现它。我用过离子4:
// tab.page.html
<ion-header >
<!-- Scrollable Segment -->
<ion-toolbar class="less-height" color="primary">
<ion-segment scrollable mode="md" (ionChange)="segmentChanged(segment)" [(ngModel)]="segment" >
<ion-segment-button mode="md" id="seg-1" value="0">
<p>Description</p>
</ion-segment-button>
<ion-segment-button mode="md" id="seg-2" value="1">
<p>Interconnections</p>
</ion-segment-button>
<ion-segment-button mode="md" id="seg-3" value="2">
<p>Declensions</p>
</ion-segment-button>
<ion-segment-button mode="md" id="seg-4" value="3">
<p>Phraseologisms</p>
</ion-segment-button>
<ion-segment-button mode="md" id="seg-5" value="4">
<p>Etymology</p>
</ion-segment-button>
<ion-segment-button mode="md" id="seg-6" value="5">
<p>Analysis</p>
</ion-segment-button>
</ion-segment>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-slides (ionSlideDidChange)="slideChanged()" class="word-slides">
<ion-slide>
<p>Slide 1</p>
</ion-slide>
<ion-slide>
<p>Slide 2</p>
</ion-slide>
<ion-slide>
<p>Slide 3</p>
</ion-slide>
<ion-slide>
<p>Slide 4</p>
</ion-slide>
<ion-slide>
<p>Slide 5</p>
</ion-slide>
<ion-slide>
<p>Slide 6</p>
</ion-slide>
</ion-slides>
</ion-content>
// tab.page.ts
@ViewChild(IonSlides) slider: IonSlides;
segment = 0;
constructor() {}
async segmentChanged(event) {
await this.slider.slideTo(this.segment);
this.slider.update();
}
async slideChanged() {
this.segment = await this.slider.getActiveIndex();
this.focusSegment(this.segment+1);
}
focusSegment(segmentId) {
document.getElementById('seg-'+segmentId).scrollIntoView({
behavior: 'smooth',
block: 'center',
inline: 'center'
});
}