Skip to content

Instantly share code, notes, and snippets.

@sters
Last active December 21, 2015 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sters/6325619 to your computer and use it in GitHub Desktop.
Save sters/6325619 to your computer and use it in GitHub Desktop.
例のアレ
(function(){
function auto_font_size($, target){
var temp = $("<div>").css({
"display" : "none",
"font-family" : target.css("font-family"),
}).text(target.text()).appendTo("body");
var maxWidth = $(window).width();
var tempWidth = temp.width();
var fontSize = parseInt(target.css("font-size"), 10);
fontSize *= maxWidth / tempWidth;
console.log(maxWidth, tempWidth, fontSize);
temp.css("font-size", fontSize + "px");
while (tempWidth >= maxWidth) {
fontSize--;
temp.css("font-size", fontSize + "px");
tempWidth = temp.width();
}
target.css("font-size", (fontSize-1) + "px");
temp.remove();
}
function exec($){
var $link =
$("<a>")
.attr("id", "link")
.attr("href", "javascript:document.forms[0].submit()")
.css({
position : "relative",
top : "-50%",
fontFamily : "mono",
})
.text("٩(๑>◡<๑)۶:.。+゚ミッコリンシャワー!!");
$("<div>").css({
width : "100%",
height : "100%",
position : "absolute",
top : 0,
left : 0,
background : "#FFF"
}).append(
$("<div>").css({
position : "relative",
top : "50%",
}).append($link)
).appendTo("body");
auto_font_size($, $link);
$(window).on("resize", function(){ auto_font_size($, $link); });
}
(function jQuery_load(){
var head = document.getElementsByTagName("head")[0];
var sc = document.createElement("script");
sc.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js";
head.appendChild(sc);
sc.onload = function(){
jQuery.noConflict();
exec(jQuery);
};
})();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment