Victa / curtain.js

PROJECT IS NOT MAINTAINED - This plugin allows you to create a web page with multiple fixed panels that unroll with an amusing effect.

Home Page:http://curtain.victorcoulon.fr

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Delaying instantiation of plugin breaks it.

Ahrengot opened this issue · comments

Hey Victor,

I'm playing around with your awesome little jQuery plugin and stumpled on this little bug:

$(function() {
    $('.curtains').curtain(); // works

    setTimeout(function() {
        $('.curtains').curtain(); // doesn't work
    }, 2000);
});

I've looked through the source but can't quite figure out why this happens. Any help is greatly appreciated :)

Found a hack-around:

$(function() {
    setTimeout(function() {
        $('.curtains').curtain(); // doesn't work
        $(window).trigger('load');
    }, 2000);
});

I saw that you listen for the window load event on line 145. Is there any way your plugin would be able to know if the window has been loaded when the plugin is inited and skip the $(window).load() step?

mhh. Maybe you can add a new option to the plugin like :

  var pluginName = 'curtain',
      defaults = {
          scrollSpeed: 400,
          bodyHeight: 0,
          linksArray: [],
          mobile: false,
          scrollButtons: {},
          controls: null,
          curtainLinks: '.curtain-links',
          enableKeys: true,
          easing: 'swing',
          timeout: 0 // add this line
    };

And change the following code

// When all image is loaded
$(window).load(function(){
    setTimeout(function(){ // add your timeout here
        self.setDimensions();
        self.$li.eq(0).addClass('current');

        if(!self.options.mobile){
            if(self.$li.eq(1).length)
                self.$li.eq(1).nextAll().css({display:'none'});
        }

        self.setEvents();
        self.setLinks();
        self.isHashIsOnList(location.hash.substring(1));
    }, self.options.timeout);
});

But, It's definitely not the better way.

Maybe can you explain me what do you want to do. We can find a better way?

I'm building a web app using Backbone.js which loads sub-pages via AJAX. on some of those subpages i want to use Curtain.js.

Using AJAX to load the pages means that window.load isn't reliable as it only fires when the first page loads.

Perhaps implementing something like the ImagesLoaded plugin (also used by Masonry) would make sense. Do you think that could work?

I just tried implemented it. It seems to work as intended. I'll see if I can figure out how to do a pull request tomorrow. :)

awesome !
I was planning to work on today. So, I'm looking forward to see your pull request :)

Finally I work few minutes on this problem. You can check the modification here 89e3427

Hope it'll help you ! tell me if not.