Last active
August 29, 2015 14:03
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*============================================ | |
= 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