Flexslider 2, how to load with (document).ready function

I use the WooThemes Flexslider 2 plugin in my WordPress framework. Here is the code:

$(window).load(function() {
    $('#flexslider-<?php echo $postid; ?>').flexslider({
        smoothHeight:   true,
        slideshow:      false,
        start: function(slider) { 
            slider.container.click(function(e) { 
                if(slider.animating) { 
                    // action
                } else {
                    slider.flexAnimate(slider.getTarget('next'));
                }
            });
        }
    });
});

The script works well with "$(window).load(function() {" If I change the "$(window).load(function() {" to "$(document).ready(function(){" the slider doesn't work. In Safari the script loads successful, but doesn't get the current image height. How to make this script to work with "$(document).ready(function(){" on all browsers ? Thanks

Answers


You can write an interval function which looks at the first image within your $('#flexslider-<?php echo $postid; ?>') element. Once it has finished loading, call the flexslider function.

This is to give you a hint, not tested:

$(document).ready(function(){
    var firstImage = $('#flexslider-<?php echo $postid; ?>').find('img').filter(':first'),
        checkforloaded = setInterval(function() {
            var image = firstImage.get(0);
            if (image.complete || image.readyState == 'complete' || image.readyState == 4) {
                clearInterval(checkforloaded);
                $('#flexslider-<?php echo $postid; ?>').flexslider({
                    // your options
                });
            }

        }, 20);

});

Need Your Help

How to let C# designer edit my struct property?

c# struct properties designer

I am creating a custom Windows Forms control in C# with several custom properties. One of those properties is a simple struct with several integral fields:

How to Add and Remove UIButtons in SubView using UISilder?

objective-c ios cocoa-touch uibutton uislider

I have a subview which is allmost half to my mainview and also I have a UISlider on my mainview . My silder has a value from 0 to 10. i want to add some UIButtons to my Subview with the UISilder.No...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.