Skip to content

Instantly share code, notes, and snippets.

@trptcolin
Forked from qrush/00_before.js
Created October 2, 2011 16:19
Show Gist options
  • Save trptcolin/1257594 to your computer and use it in GitHub Desktop.
Save trptcolin/1257594 to your computer and use it in GitHub Desktop.
coffeescript vs javascript. rewriting http://www.spookandpuff.com/examples/dynamicTextSize.html
$( document ).ready( function() {
var $body = $('body');
var setBodyScale = function() {
var scaleFactor = 0.35,
scaleSource = $body.width(),
maxScale = 600,
minScale = 30;
var fontSize = scaleSource * scaleFactor;
if (fontSize > maxScale) fontSize = maxScale;
if (fontSize < minScale) fontSize = minScale;
$('body').css('font-size', fontSize + '%');
}
$(window).resize(function(){
setBodyScale();
});
setBodyScale();
});
# based on http://www.spookandpuff.com/examples/dynamicTextSize.html
class BodyScaler
scaleFactor: 0.35
maxScale: 400
minScale: 30
constructor: ->
@body = $("body")
scale: =>
scaleSource = @body.width()
fontSize = scaleSource * @scaleFactor
if (fontSize > @maxScale)
fontSize = @maxScale
if (fontSize < @minScale)
fontSize = @minScale
@body.css("font-size", "#{fontSize}%")
$ ->
scaler = new BodyScaler()
scaler.scale()
$(window).resize(scaler.scale)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment