DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • A React Frontend With Go/Gin/Gorm Backend in One Project
  • What Is Envoy Proxy?
  • Cucumber Selenium Tutorial: A Comprehensive Guide With Examples and Best Practices
  • From On-Prem to SaaS

Trending

  • A React Frontend With Go/Gin/Gorm Backend in One Project
  • What Is Envoy Proxy?
  • Cucumber Selenium Tutorial: A Comprehensive Guide With Examples and Best Practices
  • From On-Prem to SaaS
  1. DZone
  2. Coding
  3. Frameworks
  4. Adaptive Backgrounds jQuery Plugin

Adaptive Backgrounds jQuery Plugin

Paul Underwood user avatar by
Paul Underwood
·
Mar. 05, 14 · Interview
Like (0)
Save
Tweet
Share
6.15K Views

Join the DZone community and get the full member experience.

Join For Free

I recently found a good resource for changing the background colour of a containing div. This is a jQuery plugin that will search for the most dominating colour in an image and will change it's containing element background to this colour.

Allowing you to create some nice looking showcase pages with just a few lines of Javascript.

This plugin is called the jQuery Adaptive Background Plugin.

adaptive-background

To use this jQuery plugin all you have to do is have a page with a number of images on it wrapped around a div like this.

<div class="page-slide">
    <img src="./images/water.jpg" alt="Water" data-adaptive-background='1'/>
</div>
<div class="page-slide">
    <img src="./images/water2.jpg" alt="Water 2" data-adaptive-background='1'/>
</div>
<div class="page-slide">
    <img src="./images/water3.jpg" alt="Water 3" data-adaptive-background='1'/>
</div>
<div class="page-slide">
    <img src="./images/water4.jpg" alt="Water 4" data-adaptive-background='1'/>
</div>
<div class="page-slide">
    <img src="./images/water5.jpg" alt="Water 5" data-adaptive-background='1'/>
</div>

When the plugin is ran it will search for images which have an attribute of data-adaptive-background and will find the dominate colour in these images.

To setup the Javascript to use the following you first need to download the plugin from the Github project page.

Adaptive Background Plugin

Because this is a JQuery plugin it relies on jQuery being loaded on the page before you can use it.

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="./js/jquery.adaptive-backgrounds.js"></script>
</head>

With the adaptive background plugin loaded on the page all we have to do is run the adaptiveBackground method to start the plugin.

<script>
$(document).ready(function(){
    $.adaptiveBackground.run()
});
</script>

Now you will see all the wrapper div will have a new background colour of the dominate colour in the image.

View the demo to see how this works.

Demo

JQuery

Published at DZone with permission of Paul Underwood, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • A React Frontend With Go/Gin/Gorm Backend in One Project
  • What Is Envoy Proxy?
  • Cucumber Selenium Tutorial: A Comprehensive Guide With Examples and Best Practices
  • From On-Prem to SaaS

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: