0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【ionic】ion-cardが重なってしまう対処法 ion-virtual-scroll

Posted at

なに

ionicで開発をしているがion-cardコンポーネントの1つ1つがたまに重なってしまう現象があった。
この上の階層にはion-virtual-scrollというコンポーネントを使用しており、その子要素にion-cardが存在している。

対処法

このion-virtual-scrollにitem1つ1つの高さを指定するfunctionを記述する。
そして、tsファイルの中にfunctionの記述をする。

編集前

<ion-virtual-scroll [items]="stock_list" approxItemHeight="450px">

編集後

// [itemHeight]="itemHeightFn" を追記
<ion-virtual-scroll [items]="stock_list" approxItemHeight="450px" [itemHeight]="itemHeightFn">
    /**
     * ion-cardのサイズ調整
     */
    itemHeightFn(item, index) {
        console.log('ゴリラがんばれ');
        if (window.innerWidth < 480) {
        //モバイルサイズの場合の記述
            return 280;
        }

        if (window.innerWidth <= 768 && window.innerWidth > 480) {
        //タブレットサイズの場合の記述
            return 450;
        }

        if (window.innerWidth > 768) {
        //PCサイズの場合の記述
            return 550;
        }
    }

条件のところで数字にしているところはマジックナンバーになってしまうため、あとは何かわかりやすい定数にしておく。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?