Comments (8)
Never mind. Got it working great. For any one else looking this snippet worked well for me.
$('.class-of-img-selector').on('ab-color-found', function(ev,payload){ $(".class-of-div").css({ backgroundColor: payload.color }); });
from jquery.adaptive-backgrounds.js.
You can do this with option :
parent: 'your-class-name',
from jquery.adaptive-backgrounds.js.
I am trying to apply this on the parent div for flexslider2 (http://flexslider.woothemes.com/basic-slider-with-caption.html). I have flexslider wrapped in section="featured"
Desired goal is for each slide image the section background to change color. I have tried both above mentioned but the background only works for one image and doesn't change for each slide. Any ideas how to get this working?
from jquery.adaptive-backgrounds.js.
Hi @f1ss1on,
Let me check if I understood you correctly. You got it working, ie. the background colour of the featured section matches the dominant color as required, but only for the first image. It never updates afterwards. Is that correct?
Would you happen to have a demo we can see somewhere? jsFiddle or codePen are great for this.
At any rate, if my understanding above is correct, I think you'll want to look into the properties of flexslider for some way to trigger the adaptive backgrounds at the right times. A quick check of the flexslider docs tells me there are a couple to choose from (eg. before;after).
Give that a shot and let us know how it pans out.
from jquery.adaptive-backgrounds.js.
Hi @AlfredJKwack
Sorry for the late response.
I put up a pen @ []https://codepen.io/f1ss1on/pen/pwoGJL
For
Currently on my local setup the section tag looks like the following. (it's the background of the 3rd image)
<section id="featured" class="dyn-bg ab-light" data-ab-yaq="234.979" style="background-color: rgb(240, 233, 232);">
from jquery.adaptive-backgrounds.js.
Hi,
I've loaded a new codePen for this. I think it does what you need.
The trick is to have AD run first. When it does, it sets a property data-ab-color
on each of the images. This property contains the rgb(x,y,z)
value that we need. We then use this value every time FlexSlider advances to a new slide to set the background as we like.
Below is the example in its full glory. It's far from optimised. You'll probably want to deal with blending values, transitions and other such niceties. The background changes can be quite harsh, especially since in your example, the background is static vis-a-vis the slider...
$(document).ready(function() {
// Run Adaptive background
$.adaptiveBackground.run({
parent: '1' //don't make it do anything to the background
});
// Run FlexSlider
$('.flexslider').flexslider({
animation: "slide",
start: function(slider){
$('body').removeClass('loading');
$('.flexslider').resize();
//Find the current slide and it's image
var thisSlide = slider.slides.eq(slider.currentSlide);
var thisImg = $(thisSlide).find("img");
//Take the data-ab-color property that AD set and apply it to the parent.
$('#featured').css({ background: $(thisImg).attr('data-ab-color') });
},
before: function(slider) {
// Find the current slide and it's image
var animateSlide = slider.slides.eq(slider.animatingTo);
var thisImg = $(animateSlide).find("img");
//Take the data-ab-color property that AD set and apply it to the parent.
$('#featured').css({ background: $(thisImg).attr('data-ab-color') });
}
});
});
Good luck with the implementation.
As a side-note: one thing to remember about codePen and other such tools are the CORS rules. If you load images and code needs to create a canvas from them it will fail. This is why you'll see base64 encoded images instead of what you put in.
from jquery.adaptive-backgrounds.js.
Brilliant! That worked! Thanks you!
from jquery.adaptive-backgrounds.js.
My pleasure. Glad you got what you needed.
from jquery.adaptive-backgrounds.js.
Related Issues (20)
- use rgba instead of rgb HOT 1
- imageData varies greatly between bg image and img tag HOT 2
- Getting Organized
- Apply to font colour HOT 1
- Return wrong dominant color in chrome, firefox but alright in safari HOT 6
- Parent element custom issue HOT 3
- Update Readme.MD for shade variations features HOT 4
- Respect 'opts.parent' when using 'data-ab-css-background'
- Performance with Background Images HOT 2
- Demos not work HOT 4
- Random selection for applying background-color HOT 1
- Dist folder in v1.0.3 HOT 1
- some images blocked by CORS policy HOT 2
- Any change of Video support HOT 1
- Rerunning $.adaptiveBackground.run(); ? HOT 2
- Image with wrong Dominant Colors HOT 1
- How can I extract color from the background and use it in border? HOT 1
- [question]adaptive with slidershow HOT 1
- About updating release with master branch files
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery.adaptive-backgrounds.js.