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
// EXEMPLO RODA DO MOUSE | |
/* | |
<style>div#marcador { position: absolute; top: 50%; left: 50%; width: 100px; height: 100px; margin-left: -50px; | |
margin-top: -50px; background: #f00; text-align: center; vertical-align: middle; line-height: 100px; color: #fff; } </style> | |
<div id="marcador"></div> | |
*/ | |
function handle(delta) { | |
var top = document.getElementById('marcador').style.top; | |
if (top === '') { |
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
var canvas = document.createElement('canvas'); | |
canvas.width = 900; | |
canvas.height = 600; | |
canvas.style = 'border: 1px solid black'; | |
document.body.appendChild(canvas); | |
var ctx = canvas.getContext('2d'); | |
ctx.beginPath(); | |
var x = 1; |
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
var canvas = document.createElement('canvas'); | |
canvas.width = 900; | |
canvas.height = 600; | |
canvas.style = 'border: 1px solid #00A859; background-color:#00A859'; | |
document.body.appendChild(canvas); | |
var ctx = canvas.getContext('2d'); | |
ctx.beginPath(); | |
ctx.strokeStyle = '#FFCC29'; | |
ctx.fillStyle = '#FFCC29'; |
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
// para propriedades não poderem ser deletadas | |
var objeto = {}; | |
Object.defineProperty(objeto, propertyName,{ | |
configurable: false, // define se a propriedade poderá ser alterada ou deletada | |
value: 'xpto', // o valor da propriedade | |
writable: false // define se o valor poderá ser alterado | |
// enumerable: true|false define se é listada nas propriedades do objeto | |
// set: define uma função que atribui valor a propriedade | |
// get: define uma função que retorna o valor a propriedade | |
}); |
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 writeLn(str) { | |
document.write(str + '<br>'); | |
} | |
function printProperties(strPropertieName, maxLeval) { | |
var countLevel = 1; | |
var arr = typeof strPropertieName === 'string' ? eval(strPropertieName) : strPropertieName; | |
for(var a in arr) { | |
if(typeof arr[a] === 'object' && arr[a] !== null) { | |
if(countLevel < maxLeval) { |
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
/** | |
* Retorna a quantidade de dias que faltam para uma data | |
* informada no parâmetro objDate | |
* @param {Date} objDate | |
* @returns {number} | |
*/ | |
function daysToDate(objDate) { | |
var hoje = new Date(); // data atual | |
var niverCalc = new Date(hoje); // a partir da data atual | |
niverCalc.setDate(objDate.getDate()); // define o dia do objDate |
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
/** | |
* Formata uma determinada data no padrão do objeto Date() que é o mês antes do dia (m/d/y) | |
* @param {string} strFullDate - a data no formato que desejar | |
* @param {string} strFormat - o formato da data que informou (d=day, m=month, y=year, h=hour, i=minutes, s=seconds) | |
* @returns {string} - a string no formato do javascprit (m/d/y h:i:s) | |
*/ | |
function toDateJs(strFullDate, strFormat) { | |
var regex1 = new RegExp('\/|\-|\:', 'g'); | |
var regex0 = new RegExp(' ', 'g'); | |
var arrDate = strFullDate.replace(regex0, '-').split(regex1); |
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 writeLn(str) { | |
document.write(str + '<br>'); | |
} | |
/** | |
* Formata uma determinada data no padrão do objeto Date() que é o mês antes do dia (m/d/y) | |
* @param {string} strFullDate - a data no formato que desejar | |
* @param {string} strFormat - o formato da data que informou (d=day, m=month, y=year, h=hour, i=minutes, s=seconds) | |
* @returns {string} - a string no formato do javascprit (m/d/y h:i:s) | |
*/ |
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
var hoje = new Date(); // data atual | |
var niver = new Date('12/04/' + hoje.getFullYear()); // meu aniversário | |
var dif = (niver - hoje); // diferença em milissegundos | |
var difDias = Math.round(dif/1000/60/60/24); // dias = milissegundos(1000)/segundos(60)/minutos(60)/horas(24) |
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
// atributo estático | |
var Pessoa = (function() { | |
var count = 0; // atributo estático | |
// método privado | |
var doCount = function() { count++; } | |
function Pessoa(pNome) { | |
var nome = pNome; | |
// apenas métodos gets e sets | |
this.setNome = function(val) { nome = val; } | |
this.getNome = function() { return nome; } |