flickity icon indicating copy to clipboard operation
flickity copied to clipboard

Issue with height in first time load

Open surgatekno opened this issue 7 years ago • 13 comments

hello, i love this slider so much, easy to use and have a pretty nice design too but my slider height have some issue if you are the first time visitor (mean height issue will gone if u refresh the page)

here take a look https://surgatekno.com/spek-game/spesifikasi-game-the-division-2/

and this image for example https://i.imgur.com/Vn2nzuP.jpg

i load my .css and .js on i dunno how can encountered this issue (even u load my site in front page, then u visit that page, it still have height issue, unless you refresh the page then everything will be normal) https://surgatekno.com/ my front page pleasehelp.

surgatekno avatar Feb 17 '19 03:02 surgatekno

Sounds like an imagesLoaded: true fix

desandro avatar Feb 19 '19 01:02 desandro

Sounds like an imagesLoaded: true fix

its work like a charm, thank you but next problem is the image between the slider goes smaller https://i.imgur.com/mZCJxD9.jpg its getting smaller in each slide of image

edit---- so i configure it out, it was my image size.. not same but how to force the image to show the same height ?? (also my dots in not centered as well)

surgatekno avatar Feb 19 '19 02:02 surgatekno

Same here, imageLoaded: true didn't work.

image

jsvini avatar Feb 19 '19 17:02 jsvini

@surgatekno See the demo here: https://codepen.io/desandro/pen/MYQWEe

desandro avatar Feb 20 '19 01:02 desandro

@surgatekno See the demo here: https://codepen.io/desandro/pen/MYQWEe

thank you, its work well

surgatekno avatar Mar 08 '19 11:03 surgatekno

Sounds like an imagesLoaded: true fix

Thanks bro.

coder618 avatar Nov 13 '19 12:11 coder618

some case's this issue still appear, Despite of adding : {imagesLoaded: true} , I fix fix the issue by giving a css width value in the parent div. Hope that would be helpful.

coder618 avatar Dec 31 '19 06:12 coder618

In some cases this issue still appears, Despite of adding {imagesLoaded: true},

The Fix is, imagesLoaded requires the flickity-imagesloaded package. It already is included with flickity.pkgd.js, but not with Flickity as a stand-alone package. If you are using Webpack or RequireJS without flickity.pkgd.js, you need to install and require flickity-imagesloaded separately.

npm install flickity npm install flickity-imagesloaded

var Flickity = require('flickity');
require('flickity-imagesloaded');

var flkty = new Flickity( '.carousel', {
  imagesLoaded: true
});

For Angular 4 to 8:

npm install flickity npm install flickity-imagesloaded npm install @types/node

tsconfig.app.json: ( add "types": ["node"] )

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": ["node"]  
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "src/test.ts",
    "src/**/*.spec.ts"
  ]
}

.ts:

import { Component, OnInit, Inject, AfterViewInit } from '@angular/core';
import { DOCUMENT } from '@angular/common';
import * as Flickity from 'flickity';
require('flickity-imagesloaded');

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss']
})

export class HomeComponent implements OnInit, AfterViewInit {

  constructor(@Inject(DOCUMENT) private document: Document) { }

  ngOnInit() {
 }

  ngAfterViewInit() {
    this.initializeFlickitySlider();
  }

  initializeFlickitySlider() {
    var elem = this.document.querySelector('.main-carousel');
    new Flickity(elem, {
      autoPlay: true,
      imagesLoaded: true,
      wrapAround: true
    })
  }
}

.html:

<div class="main-carousel">
   <div class="carousel-cell col-xl-3 col-lg-4 col-md-5 col-9 pb-1">
       <div class="card">
          <div class="card-body">
                <!---->
          </div>
       </div>
    </div>
</div>

For more information, https://flickity.metafizzy.co/extras.html#module-loaders

Hope that would be helpful.

PrasathRavichandran avatar Feb 14 '20 07:02 PrasathRavichandran

$(window).on('load', function(){ //create flickity }); has given me a lot of success in the past, without including another library.

clarknelson avatar Feb 18 '20 19:02 clarknelson

Rather that using window load to initialize Flickity, you can use it to trigger resize, so Flickity gets initialized soon, then resizes after all media has been loaded.

let $carousel = $('.carousel').flickity({});

$(window).load( function() {
  $carousel.flickity('resize');
});

desandro avatar Mar 29 '20 15:03 desandro

Ah yes, thank you!

clarknelson avatar Mar 29 '20 15:03 clarknelson

I use resize function in my vue project and worked for me in template section

<flickity ref="flickity"  :options="flickityOptions">
      // show something here <3
</flickity>

in data section

data() {
   return {
           flickityOptions: {
                imagesLoaded: true,
            }
    }
}

in mounted section

    mounted() {
        this.$nextTick(() => {
            let _this = this;
            document.addEventListener("readystatechange", event => {
                if (event.target.readyState === "complete") {
                    _this.$refs.flickity.resize();
                }
            });
        });
    }

mihalidis avatar Aug 19 '21 16:08 mihalidis

Adding a min-height: 100%; width:100%; to my gallery cells solved the problem.

dpw1 avatar Sep 24 '24 17:09 dpw1