在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:briangonzalez/jquery.adaptive-backgrounds.js开源软件地址:https://github.com/briangonzalez/jquery.adaptive-backgrounds.js开源编程语言:JavaScript 95.6%开源软件介绍:
A simple jQuery plugin to extract the dominant color of an image and apply it to the background of its parent element. Getting StartedInstall via bower:
Then simply include jQuery and the script in your page, and invoke it like so: $(document).ready(function(){
$.adaptiveBackground.run();
}); The script looks for image(s) with the <img src="/image.jpg" data-adaptive-background> Using an element with a CSS background imageInstead of using an Enable this functionality by adding a data property, <div style='background-image: url(/some-image.jpg)' data-adaptive-background data-ab-css-background></div> DemoHere's a little demo of how it works. (1) The page loads (2) the dominant background color of the image is extracted (3) said color is applied to parent of image. Demo drastically slowed down to show effect. APIThis plugin exposes one method:
Default Options
Example:
Call the var defaults = {
selector: '[data-adaptive-background="1"]',
parent: null,
exclude: [ 'rgb(0,0,0)', 'rgba(255,255,255)' ],
shadeVariation: false,
shadePercentage: 0,
shadeColors: {
light: 'rgb(255,255,255)',
dark: 'rgb(0,0,0)'
},
normalizeTextColor: false,
normalizedTextColors: {
light: "#fff",
dark: "#000"
},
lumaClasses: {
light: "ab-light",
dark: "ab-dark"
},
transparent: null
};
$.adaptiveBackground.run(defaults) Events Emitted
Example:
Bind to the $('img.my-image').on('ab-color-found', function(ev,payload){
console.log(payload.color); // The dominant color in the image.
console.log(payload.palette); // The color palette found in the image.
console.log(ev); // The jQuery.Event object
}); Success CallbackYou may wish to supply a callback function which is called once the magic has been performed. $.adaptiveBackground.run({
success: function($img, data) {
console.log('Success!', $img, data);
}
}); Note, this callback is called once for each image. CaveatsThis plugin utlizes the Enabling CORS on S3 To enable CORS for images hosted on S3 buckets, follow the Amazon guide here; adding the following to the bucket's CORS configuration: <CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
</CORSRule> For all images, you can optionally also include a cross-origin attribute in your image. This is not absolutely necessary since the <img src="/image.jpg" data-adaptive-background cross-origin="anonymous"/> CreditThis plugin is built on top of a script called RGBaster. Collaborators
This project exists thanks to all the people who contribute. [Contribute]. BackersThank you to all our backers! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论