From 1d9709915a5f5becb4d045372668723921b8be7e Mon Sep 17 00:00:00 2001 From: Andrew Kos Date: Wed, 10 Sep 2014 13:22:31 -0500 Subject: [PATCH] Some fixes and update to docts --- README.md | 1 + comcastify.js | 15 ++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 43f3fb3..a1a1539 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ With all this internet going around, sometimes you just want to experience the t }); ``` 4. Switch up parameters to change your experience: + * **elements** list of DOM elements to limit comcastification to. * **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. diff --git a/comcastify.js b/comcastify.js index 69d833f..54f9474 100644 --- a/comcastify.js +++ b/comcastify.js @@ -6,7 +6,7 @@ var comcastifyjs = (function () { // calculate new height var newTopClip = slowloadDiv.slothifyData.imageTopClip + args.loadIncrement; - var img = slowloadDiv.previousSibling; + var img = slowloadDiv.slothifyData.img; slowloadDiv.style.width = img.offsetWidth + 'px'; slowloadDiv.style.height = img.offsetHeight + 'px'; slowloadDiv.style.top = img.offsetTop + 'px'; @@ -15,18 +15,14 @@ var comcastifyjs = (function () { // update slowload div slowloadDiv.style.clip = 'rect(' + newTopClip + 'px auto auto auto)'; + // check stopping conditions + var maxImageHeight = img.height * args.loadMaxPercent; if (!img.complete) { setTimeout(slowloadModiferCallback(slowloadDiv, args), args.loadSpeed); - } - if (typeof img.naturalHeight !== "undefined" && img.naturalWidth === 0) { + } else if (typeof img.naturalHeight !== "undefined" && img.naturalWidth === 0) { setTimeout(slowloadModiferCallback(slowloadDiv, args), args.loadSpeed); - } - - // check stopping conditions - var maxImageHeight = img.height * args.loadMaxPercent; - - if (!maxImageHeight || maxImageHeight === 0 || newTopClip < maxImageHeight) { + } else if (!maxImageHeight || maxImageHeight === 0 || newTopClip < maxImageHeight) { // create new update timeout slowloadDiv.slothifyData.imageTopClip = newTopClip; setTimeout(slowloadModiferCallback(slowloadDiv, args), args.loadSpeed); @@ -72,6 +68,7 @@ var comcastifyjs = (function () { // remember what the max height should be for later calculation slowload.slothifyData = { + img: img, imageTopClip: 0, maxImageHeight: img.height * params.loadMaxPercent };