How to hide images until AFTER jquery flexslider finishes loading
Asked Answered
S

6

10

I tried to integrate wootheme's Flexslider on my site and it looks/works great except for when it is loading.

When you refresh the page with the slider, before flexslider loads (about 1 second) the first slide appears very big and flashes to black then dissapears and then the carousel appears.

I think the image is loading faster than the jquery? How can I hide the image unti jquery loads (like on the demo website, even if i refresh 3 billion times, the problem is never repeated on their website, it all loads gracefully! - http://flexslider.woothemes.com/carousel-min-max.html )

I loaded the flexlisder.js right after jquery and copied the same html code from the demo (to match the .css file that is also loaded. And here is the init code I am using - from the demo site also:

$(document).ready(function() {

  $('.flexslider').flexslider({
    animation: "slide",
    animationLoop: false,
    itemWidth: 210,
    itemMargin: 5,
    minItems: 2,
    maxItems: 4
  });
});
Soulsearching answered 1/2, 2013 at 21:56 Comment(0)
B
22

You need to deal with the callback functions for the plugin you are using hide all the images from CSS by using a class let's say flexImages

$(document).ready(function() {

  $('.flexslider').flexslider({
    animation: "slide",
    animationLoop: false,
    itemWidth: 210,
    itemMargin: 5,
    minItems: 2,
    maxItems: 4, 
    start: function(){
         $('.flexImages').show(); 
    },
  });
});
Boreas answered 1/2, 2013 at 22:4 Comment(2)
Thank you so much! that did the trick! Woothemes didn't mention doing that, yet their demos work perfect regardless!Soulsearching
I am glad it helped, but my advice to you is when you face such problems with plugins or such stuff read about their callbacks it really will help :)Boreas
H
6

Set the default style for "display" to "none". using show() will change this style value.

Hoad answered 1/2, 2013 at 22:1 Comment(1)
I want to add: It is important to do this on <li> elements.Queri
P
1

Also Found that the slides flash before loading and display stacked down the page with list item bullets.

Only for a second. Then it worked fine. I didn't realize I hadn't included the flexslider.css file because I had already turned of any navigation that would have shown broken nav img links.

Remember to Include the CSS!

Pizor answered 3/12, 2013 at 18:1 Comment(0)
T
1

… i had the same problem, tried the js solution above - it worked well but then i realized when js is disabled for some reason - that nothing will be shown up, so i decided to look for a non js solution:

i just put some thing like that for the specific slider:

.MySlider {
  .flexslider .slides img { 
  max-height: 400px; 
  width: 940px;
 }
}

worked well, even responsive. Hope that may help!

Timm answered 21/4, 2015 at 17:3 Comment(0)
N
0

I experienced a similar issue when I forgot to include the flexslider.css

Nadeau answered 29/5, 2013 at 15:12 Comment(0)
J
0

I just set in the CSS of the div that contains the slider: overflow:hidden ; height: the height of the images you use, then it works perfect!

update: this is not a responsive solution as the slider changes the size... what can I do??

Jarlath answered 18/3, 2014 at 16:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.