Skip to content

Instantly share code, notes, and snippets.

@digiltd
Last active August 29, 2015 14:03
Show Gist options
  • Save digiltd/6b49ec8785f37e34063d to your computer and use it in GitHub Desktop.
Save digiltd/6b49ec8785f37e34063d to your computer and use it in GitHub Desktop.
Add the color attributes to holder.js data-src using David Merfield's loverly Random Color script.
/*============================================
= Random colour picker =
============================================*/
/**
*
*
Description
Adds two colours to your holder.js image and used the contents of the P tag as the placeholder text
Requirements
https://github.com/imsky/holder
https://github.com/davidmerfield/randomColor
Usage
<div class="col-sm-7">
<img class="rand-colors" data-src="holder.js/100x300/"><p>text goes here</p>
</div>
*
**/
$(document).ready(function() {
$(".rand-colors").each(function() {
//background color
var rndColor1 = randomColor({
luminosity: 'dark'
//hue: 'pink'
});
//text color
var rndColor2 = randomColor({
luminosity: 'light'
});
var imgSrc = $(this).attr('data-src');
//get the contents from the p
var placeText = $(this).parent().find('p').text();
$(this).attr('data-src', imgSrc + '\/' +
rndColor1 +
':' + rndColor2 + '\/' +
"text" +
':' + placeText);
//remove p from dom
$(this).parent().find('p').remove();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment