Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Added image prep function
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Kos committed Sep 9, 2014
1 parent 28960df commit c63709b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ With all this internet going around, sometimes you just want to experience the t

```<script src="http://code.onion.com/comcastify.js"></script>```

2. Initialize comcastify on window load, something like this (so image sizes are properly calculated):
2. Prepare the images on your page on document ready (so images don't show up before the box):

```
window.onload = comcastifyjs.fixMyImagesLoadingSoFast({
comcastifyjs.letsPrepareTheseImages();
```
3. Initialize comcastify on window load (so image sizes are properly calculated):
```
comcastifyjs.fixMyImagesLoadingSoFast({
boxColor: '#123456',
loadMaxPercent: 0.75,
loadSpeed: 100,
loadIncrement: 5
});
```
3. Switch up parameters to change your experience:
4. Switch up parameters to change your experience:
* **boxColor** Hex color for the box placed over images.
* **loadMaxPercent** Max percentage of image to load.
* **loadSpeed** Speed to load your images to their max in ms.
Expand Down
13 changes: 13 additions & 0 deletions comcastify.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ var comcastifyjs = (function () {
};
};

var prepare = function () {
// hide images so image doesn't show up before box
var imgs = document.getElementsByTagName('img');
for(var i = 0; i < imgs.length; i++) {
var img = imgs[i];
img.style.visibility = 'hidden';
}
};

var slowImages = function (args) {
return function () {
var params = {
Expand Down Expand Up @@ -58,6 +67,9 @@ var comcastifyjs = (function () {
// put box over image
parent.appendChild(slowload);

// show image again
img.style.visibility = 'visible';

if (params.loadMaxPercent > 0.0) {
// slowload using timeout since this is nicer to the browser :)
setTimeout(slowloadModiferCallback(slowload, params), params.loadSpeed);
Expand All @@ -67,6 +79,7 @@ var comcastifyjs = (function () {
};

return {
letsPrepareTheseImages: prepare,
fixMyImagesLoadingSoFast: slowImages
};

Expand Down

0 comments on commit c63709b

Please sign in to comment.