kennethcachia / background-check

Automatically switch to a darker or a lighter version of an element depending on the brightness of images behind it.
http://kennethcachia.com/background-check/
MIT License
3.27k stars 282 forks source link

FlexSlider #4

Closed h0r0m4n closed 10 years ago

h0r0m4n commented 10 years ago

Has anyone was able to make it work with FlexSlider 2?

albi commented 10 years ago

nope. it will check only the first slide. although i've said "images: .flex-active-slide > img"

BackgroundCheck.init({ targets: '.flex-direction-nav a', images: '.flex-active-slide > img' });

kennethcachia commented 10 years ago

Sliders are tricky!

Apart from calling BackgroundCheck.init() on load, you also need to call Background.refresh() after each transition to reprocess targets. FlexSlider has an after attribute which is a function called after each slide transition, and can be used as follows:

$('.slider').flexslider({
  animation: 'slide',
  start: function () {
    BackgroundCheck.init({
      targets: '.flex-direction-nav li a',
      images: '.slides img'
    });
  },
  after: function () {
    BackgroundCheck.refresh();
  }
});

Check out this demo - code available here.

albi commented 10 years ago

That's exactly what I do. But it won't work with flexslider. The refresh will only check the first image and not the active slide as the debug info will show that.

kennethcachia commented 10 years ago

Hm.. do you have an online version that I can debug?

albi commented 10 years ago

For sure: http://kunden.alexanderalbrecht.ch/zeh/textseite.html debug is set to true

here is what i run for flexslider.

$('.flexslider').flexslider({
    animation: "fade",          
    easing: "swing",            
    direction: "horizontal",    
    animationLoop: true,        
    slideshow: true,            
    slideshowSpeed: 7000,       
    animationSpeed: 300,        
    pauseOnHover: true,         
    pauseInvisible: true,       
    useCSS: true,               
    touch: true,                
    controlNav: false,          
    prevText: "Vorheriges Bild",
    nextText: "Nächstes Bild",  
    keyboard: true,             

    // Callback API
    start: function(){
        BackgroundCheck.init({
            targets: '.flex-direction-nav a',
            images: '.flex-active-slide > img',
            debug: true
        });
    },
    after: function(){
        BackgroundCheck.refresh();
    }
});
kennethcachia commented 10 years ago

Try the following instead so that all images are processed instead of just the first (active) image:

BackgroundCheck.init({
  targets: '.flex-direction-nav a',
  images: '.slides img'
});

You should also switch to v1.1.2 as it fixes previous issues with stacked images. Demo.