How to make ion-slide responsive? - ionic-framework

My ionic app has a slider with 2 slides, and they show up based on left and right swipe action. I want to make my page responsive. In case of large screen i want to show both slides side-by-side and swipe action to be disabled. How can i achieve this?

I think you want to do this so far
<ion-slides autoplay="5000" loop="true" speed="3000" class="full">
<ion-slide>
<img src="assets/img/gym.jpg" />
</ion-slide>
</ion-slides>
This code auto-change your images with the slide animation and it is more responsive also

Responsive grid view is working fine for me here
<ion-content padding class="page-manhomeslider">
<ion-slides autoplay="5000" loop="false" speed="1000" (ionSlideDidChange)="slideChanged()">
<ion-slide>
<ion-grid>
<ion-row>
<ion-col text-left>
<ion-label style="color: black">1/12</ion-label>
</ion-col>
</ion-row>
<img src="assets/gif/men/1-jumping-jacks.gif" class="slide_img"/>
<ion-row>
<ion-col class="pageheader">
<h2>Jumping Jacks</h2>
</ion-col>
</ion-row>
<ion-footer>
<ion-row>
<ion-col>
</ion-col>
<ion-col>
<div id="countdown">
<div class="countdown-number"></div>
<svg>
<circle r="28" cx="40" cy="40"></circle>
</svg>
</div>
</ion-col>
<ion-col>
<ion-buttons class="btnend" end>
<button (click)="goToSlide2()" ion-button round>
<ion-icon name="arrow-forward"></ion-icon>
</button>
</ion-buttons>
</ion-col>
</ion-row>
</ion-footer>
</ion-grid>
</ion-slide>

In React, I used states to update the slidesPerView property whenever the page is resized.
export default function ResponsiveSlides () {
const [slideOpts, setSlideOpts] = useState ({
initialSlide: 0,
speed: 400,
slidesPerView: Math.floor (window.innerWidth / 298),
spaceBetween: 1
});
function changeSlideOpts (key, value) {
setSlideOpts (
{
... slideOpts,
[key]: value
}
)
}
window.onresize = function (event) {
changeSlideOpts ("slidesPerView", Math.floor (window.innerWidth / 298));
};
return (
<IonSlides pager = {false} options = {slideOpts}>
<IonSlide>
<IonCard />
</IonSlide>
<IonSlide>
<IonCard />
</IonSlide>
<IonSlide>
<IonCard />
</IonSlide>
<IonSlide>
<IonCard />
</IonSlide>
<IonSlide>
<IonCard />
</IonSlide>
<IonSlide>
<IonCard />
</IonSlide>
</IonSlides>
)
}

Related

ionic - ion-grid within slides, responsive is not working

I have problem with ionic grid within slides. I have items of product where i put on ion-grid, and ion-grid is within slides, then if i rotate my android device, ion-grid is not responsive, so the image is cut off
<ion-col class="hide-xs" size-sm="7" >
<ion-slides >
<ion-slide *ngFor="let products of listProduct" >
<app-ajax [ajax]="ajax"></app-ajax>
<ion-grid>
<ion-row>
<ion-col size="6" sizeMd="4" sizeXl="3" *ngFor="let item of products">
<div class="image-container" *ngIf="item.photo!==''">
<ion-img *ngIf="item.idproduct !==0" width="100%" height="100%"
[src]="'data:image/jpeg;base64,' + item.foto64" (click)="presentModal(item)"></ion-img>
</div>
<div class="fontImage" (click)="presentModal(item)">{{item.nmproduct}}</div>
</ion-col>
</ion-row>
</ion-grid>
</ion-slide>
</ion-slides>
</ion-col>
if i removed ion-slides, ion-grid responsive properly, so the image is not cut off. how to solve this? thankyou
you can give this in component.ts
#ViewChild('slides',{static: true}) slides;
#HostListener('window:resize')
onResize() {
setTimeout(() => this.slides.update(), 50);
}

ionic header, how to use whole screen

The following is my ionic header code. I have the SVG in the ion-item element, which has ion-no-padding class.
Somehow, there is still space to the right, and a line below. Any hints as to why? I am quite new at ionic, so spending a lot of time in docs.
<ion-header class="ion-no-border">
<ion-item lines="none">
<ion-avatar slot="end">
<img src="assets/profile.jpg">
</ion-avatar>
<ion-button fill="clear" color="light">
<ion-icon slot="icon-only" name="menu"></ion-icon>
</ion-button>
</ion-item>
<ion-item lines="none">
<div class="ion-padding-start ion-padding-bottom">
<ion-label>
<h2>Choose a Car</h2>
</ion-label>
<ion-row class="ion-align-items-center">
<ion-col size="10">
<ion-searchbar placeholder="Oman, Muscat" searchIcon="location-outline"></ion-searchbar>
</ion-col>
<ion-col size="2">
<ion-button color="light" fill="clear">
<ion-icon slot="icon-only" name="options-outline"></ion-icon>
</ion-button>
</ion-col>
</ion-row>
</div>
</ion-item>
<ion-item expandable=true class="ion-no-padding">
<svg style="pointer-events: none" class="wave" width="100%" height="50px" preserveAspectRatio="none"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1920 75">
<defs>
<svg:style type="text/css">
<![CDATA[
.a {fill: none}.b {clip-path: url(#a)}.c,.d {fill: hsla(234, 20%, 95%, 1)}.d {opacity: 0.5;isolation: isolate;}
]]>
</svg:style>
<clipPath id="a"><rect class="a" width="1920" height="75"></rect></clipPath></defs>
<g class="b"><path class="c" d="M1963,327H-105V65A2647.49,2647.49,0,0,1,431,19c217.7,3.5,239.6,30.8,470,36,297.3,6.7,367.5-36.2,642-28a2511.41,2511.41,0,0,1,420,48"> </path> </g>
<g class="b"><path class="d" d="M-127,404H1963V44c-140.1-28-343.3-46.7-566,22-75.5,23.3-118.5,45.9-162,64-48.6,20.2-404.7,128-784,0C355.2,97.7,341.6,78.3,235,50,86.6,10.6-41.8,6.9-127,10"> </path> </g>
<g class="b"><path class="d" d="M1979,462-155,446V106C251.8,20.2,576.6,15.9,805,30c167.4,10.3,322.3,32.9,680,56,207,13.4,378,20.3,494,24"> </path></g>
<g class="b"><path class="d" d="M1998,484H-243V100c445.8,26.8,794.2-4.1,1035-39,141-20.4,231.1-40.1,378-45,349.6-11.6,636.7,73.8,828,150"></path></g>
</svg>
</ion-item>
</ion-header>
ion-item {
--inner-padding-end:0px
}
I found the inner-padding was 16px, affecting the ion-item in the header. Problem solved.

ionic 4 keyboard pushes the content

i am using ionic 4 and when the input has focus the keyboard shows and pushes the screen up and i am not able to scroll the html design smash and will not look good
hers the code i am using
<ion-header no-border>
<ion-toolbar>
<ion-row id="progressbar" class="top-bar">
<app-progress [progress]="loadProgress"></app-progress>
</ion-row>
<ion-buttons slot="start">
<ion-back-button class="back-button" *ngIf="back" mode="ios" icon="ios-
arrow-back" color="dark"
(click)="backSlide()"></ion-back-button>
</ion-buttons>
<ion-buttons slot="end" mode="md">
<ion-button class="page-numbering" mode="md">
<span class="first-page-number textBlack">{{pageNumber}}</span><span
class="second-page-number normal">/5</span>
</ion-button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content [ngClass]="{'no-padding-div': isIonContent, 'padding-div': !isIonContent}"
force-overscroll="false" fixed="true">
<ion-slides [options]="slideOpts" #slides>
<ion-slide>
<ion-grid id="profileGrid">
<ion-row id="containerRow">
<ion-col no-padding>
<form [formGroup]="profileForm" class="formStyle">
<ion-row id="title-message" class="info-box-profile">
<ion-row class="welcome-title medium" justify-content-center><ion-label></ion-label></ion-row>
<ion-row class="welcome-sbtitle normal" justify-content-center><ion-label></ion-label></ion-row>
</ion-row>
<ion-row id="fname">
<p class="box-titles normal">What’s your first name?</p>
<ion-item mode="md">
<ion-input class="normal" formControlName="First_Name" placeholder="First name" id="name" mode="md"></ion-input>
</ion-item>
</ion-row>
<ion-row id="bday" align-items-start>
<p class="box-titles normal">When is your birthday?</p>
<ion-item mode="md">
<ion-datetime #picker class="normal timePicker" formControlName="Date_Of_Birth" displayFormat="MM/DD/YYYY"
Placeholder="Date of birth" pickerFormat="MM/DD/YYYY" [(ngModel)]="date"
(ionChange)="picktime($event)" mode="md"></ion-datetime>
<ion-icon class="arrow-down-icon" name="ios-arrow-down" slot="end"></ion-icon>
</ion-item>
</ion-row>
<ion-row align-items-start id="gender-title">
<p class="box-titles normal">Which one are you?</p>
</ion-row>
<ion-row id="gender-row" justify-content-center>
<ion-col align-self-center size="6">
<div (click)="female()" class="female" [ngClass]="{'female-image': gender == '', 'female-image1': gender == 'female', 'female-image2': gender == 'male'}">
</div>
</ion-col>
<ion-col align-self-center size="6">
<div (click)="male()" class="male" [ngClass]="{'male-image': gender == '', 'male-image1': gender == 'male', 'male-image2': gender == 'female'}">
</div>
</ion-col>
</ion-row>
<ion-row id="next-button" justify-content-center>
<ion-button class="cta" shape="round" color="secondary" expand="full"
[disabled]="(profileForm.valid) ? false : true" (click)="onClick()">
Next
</ion-button>
<!-- <ion-button class="cta" shape="round" color="secondary" expand="full"
[disabled]="(profileForm.valid && gender != '') ? false : true" (click)="onClick()">
Next
</ion-button> -->
</ion-row>
</form>
</ion-col>
</ion-row>
</ion-grid>
</ion-slide>
<ion-slide>
....
</ion-slides>
</ion-content>
when i click on the first name input the keyboard pushes the screen up and the content smashes, i tried many solution but none of them worked for me
and i also added this in my app.module.ts
IonicModule.forRoot({
mode: 'ios',
scrollAssist: false,
scrollPadding: false,
}),

Ionic list with button and checkbox in same line

I'm trying to have a ion-list with button and checkbox or radio at the end of the line.
That's my code without checkbox/radio:
<button ion-item (click)="editItem(i, item)">
<ion-avatar item-start>
<img [src]="item.photo" />
</ion-avatar>
<h2>{{item.name}}</h2>
<p>{{item.info}}</p>
</button>
It works and I can show any information about Item object.
If I add checkbox or radio my info disappear and the button click don't work (always checkbox change event trigger).
<button ion-item (click)="editItem(i, item)">
<ion-avatar item-start>
<img [src]="item.photo" />
</ion-avatar>
<h2>{{item.name}}</h2>
<p>{{item.info}}</p>
<ion-checkbox (ionChange)="fireEvent(i, $event)"></ion-checkbox>
</button>
How can I have a button and checkbox in same row ?
You can use the grid system to put elements on the same row:
<ion-grid>
<ion-row>
<ion-col>
<button ion-item (click)="editItem(i, item)">
<ion-avatar item-start>
<img [src]="item.photo" />
</ion-avatar>
<h2>{{item.name}}</h2>
<p>{{item.info}}</p>
</button>
</ion-col>
<ion-col>
<ion-checkbox (ionChange)="fireEvent(i, $event)"></ion-checkbox>
</ion-col>
</ion-row>
</ion-grid>
more info here:
https://ionicframework.com/docs/api/components/grid/Grid/

Ion-slides error on ionic 3

I'm getting a problem using ion-slides on Ionic 3.
It's using all my screen size, but when i scroll down there is all my stuft and it is ok, but i need those slides be smaller
This is my code:
<ion-header>
<ion-navbar>
<ion-title>
Productos
</ion-title>
<ion-buttons end>
<button (click)="reloadProducts()" style="background:none" ion-button round full large text-center icon-right> <!--(click)="imeiViewer()"-->
<ion-icon name="cart"></ion-icon>
<ion-badge *ngIf="itemInfoHeader.length > 0" id="cart-badge">{{itemInfoHeader.length}}</ion-badge>
</button>
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-slides pager>
<ion-slide style="width:100%; height: 50%; " *ngFor="let slide of slide_items" >
<div>
<img src="assets/img/{{slide}}.png">
</div>
</ion-slide >
</ion-slides>
<ion-grid>
<ion-row>
<ion-col col-6>
<button ion-button block icon-start>Filtrar
<ion-icon name="options"></ion-icon>
</button>
</ion-col>
<ion-col col-6>
<button ion-button block icon-end>Ordenar
<ion-icon name="reorder"></ion-icon>
</button>
</ion-col>
</ion-row>
</ion-grid>
<ion-col col-6 col-md-4 col-xl-3 *ngFor="let producto of itemInfo">
<ion-item class="item-thumbnail-left" >
<ion-grid>
<ion-row>
<ion-col col-6>
<img src="http://186.176.206.154:8088/images/Products/{{producto.ItemId}}_l_.PNG" >
</ion-col>
<ion-col col-6>
<h3>{{producto.ItemId}}</h3>
<ion-item class="item item-text-wrap">{{producto.ItemName}}</ion-item>
<p style="position:absolute;right:10px;">
<button ion-button (click)="addToCart(producto)" icon-end >
<ion-icon name="cart"></ion-icon>
</button>
</p>
</ion-col>
</ion-row>
</ion-grid>
</ion-item>
</ion-col>
</ion-content>
if anyone knows how to make my slides "circles" goes up. I tried reducing Height but it doesn't work.
I am using this as guide -> https://ionicframework.com/docs/components/#slides
Fixed! I had to add style="height: 300px;" on ion-slides.