-
-
Save paulodiovani/0d48d8b7b2556c34aabd to your computer and use it in GitHub Desktop.
Script para exibir tamanho do viewport. Fontes em CoffeeScript, Javascript gerado e Javascript minificado (para usar num botão de atalho)
This file contains hidden or 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
id = "viewport-size-by-edmundojr-paulodiovani" | |
# Cria o elemento do viewport, se ainda não existir | |
create = -> | |
div = document.getElementById(id) || document.createElement "div" | |
div.id = id | |
div.style.cssText = """ | |
position:fixed; \ | |
top:0; \ | |
right:0; \ | |
padding:0 .5em; \ | |
color:#333; \ | |
background:rgba(255,255,255,.75); \ | |
font:14px/1.8em Monaco, Inconsolata, Ubuntu Mono, Courier New, monospaced; | |
z-index:9999; | |
""" | |
div.innerText = div.textContent = get_dimensions() | |
document.body.appendChild div | |
return | |
# obtém as dimensões do viewport | |
get_dimensions = -> | |
window.innerWidth + 'x' + window.innerHeight | |
# atualiza o texto das dimensões no elemento | |
resize = -> | |
div = document.getElementById(id) | |
div.innerText = div.textContent = get_dimensions() | |
# adiciona como evento ao resize da window | |
window.onresize = resize | |
create() |
This file contains hidden or 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
// Generated by CoffeeScript 1.7.1 | |
(function() { | |
var create, get_dimensions, id, resize; | |
id = "viewport-size-by-edmundojr-paulodiovani"; | |
create = function() { | |
var div; | |
div = document.getElementById(id) || document.createElement("div"); | |
div.id = id; | |
div.style.cssText = "position:fixed; top:0; right:0; padding:0 .5em; color:#333; background:rgba(255,255,255,.75); font:14px/1.8em Monaco, Inconsolata, Ubuntu Mono, Courier New, monospaced;\nz-index:9999;"; | |
div.innerText = div.textContent = get_dimensions(); | |
document.body.appendChild(div); | |
}; | |
get_dimensions = function() { | |
return window.innerWidth + 'x' + window.innerHeight; | |
}; | |
resize = function() { | |
var div; | |
div = document.getElementById(id); | |
return div.innerText = div.textContent = get_dimensions(); | |
}; | |
window.onresize = resize; | |
create(); | |
}).call(this); |
This file contains hidden or 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
(function(){var create,get_dimensions,id,resize;id="viewport-size-by-edmundojr-paulodiovani";create=function(){var div;div=document.getElementById(id)||document.createElement("div");div.id=id;div.style.cssText="position:fixed; top:0; right:0; padding:0 .5em; color:#333; background:rgba(255,255,255,.75); font:14px/1.8em Monaco, Inconsolata, Ubuntu Mono, Courier New, monospaced;\nz-index:9999;";div.innerText=div.textContent=get_dimensions();document.body.appendChild(div)};get_dimensions=function(){return window.innerWidth+'x'+window.innerHeight};resize=function(){var div;div=document.getElementById(id);return div.innerText=div.textContent=get_dimensions()};window.onresize=resize;create()}).call(this); |
Troca o position:absolute
para position:fixed
e adiciona z-index:9999;
.
Trocado.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Para criar um bookmarklet:
"Viewport Size"
no nome (ou oq ue preferir)javascript:
no endereço, e cole o código deviewport.min.js
a seguir