-
-
Save reneruiz/0fba9f66049c5c8e51b4 to your computer and use it in GitHub Desktop.
preventScroll not working reliabily
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
var ajax = (function() { | |
// Private | |
var httpRequest, data, | |
ajaxState = { | |
isDone : 4, | |
isOkay : 200 | |
}, | |
successHandler = function(data) { | |
var json = JSON.parse(data); | |
getRandomKey(json); | |
}, | |
errorHandler = function() { | |
console.log("Error: Status is not reporting 'Okay'"); | |
}, | |
getRandomKey = function(array) { | |
var totalKeys = array.length; | |
if (totalKeys > 0) { | |
var randomKey = random(totalKeys); | |
} | |
templify(array[randomKey], ".headline"); | |
}, | |
templify = function(entry, element) { | |
var container = document.querySelector(element); | |
container.innerHTML = entry; | |
}, | |
random = function(int) { | |
return Math.floor(Math.random() * int); | |
}; | |
// Public | |
var makeRequest = function(method, url) { | |
if (window.XMLHttpRequest) { | |
httpRequest = new XMLHttpRequest(); | |
} else if (window.ActiveXObject) { | |
try { | |
httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); | |
} | |
catch (e) { | |
try { | |
httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); | |
} | |
catch (e) {} | |
} | |
} | |
httpRequest.open(method, url, true); | |
httpRequest.onreadystatechange = function () { | |
if (httpRequest.readyState === ajaxState.isDone) { | |
if (httpRequest.status === ajaxState.isOkay) { | |
data = httpRequest.responseText; | |
successHandler(data); | |
} else { | |
errorHandler(); | |
} | |
} | |
}; | |
httpRequest.send(); | |
}; | |
return { | |
request: makeRequest | |
}; | |
})(); |
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
var preventScroll = (function() { | |
var resize = function(el) { | |
var element = document.querySelector(el), | |
style = window.getComputedStyle(element), // element.style.fontSize doesn't work | |
fontsize = parseFloat(style.fontSize); | |
// console.log(document.body.scrollHeight + " > " window.innerHeight); | |
while (document.body.scrollHeight > window.innerHeight) { | |
fontsize = fontsize - 1; // For some reason 'fontsize--;' doesn't work | |
element.style.fontSize = fontsize + 'px'; | |
} | |
}; | |
return { | |
resize: resize | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment