Hello. I have a variable with a value of 0 and a window of size 1000. I would like to resize for smaller sizes, 999, 998, 997, the variable if it decremented by getting -1, -2 ... And in resize for bigger, it if it increased, 1, 2 ... Any help?
Hello. I have a variable with a value of 0 and a window of size 1000. I would like to resize for smaller sizes, 999, 998, 997, the variable if it decremented by getting -1, -2 ... And in resize for bigger, it if it increased, 1, 2 ... Any help?
Create a variable that stores this value and joins an event sink for when the window changes size. You also need a way to fetch information from the current window size. I do not quite understand your question if you want the width (x) or the height (y). Next an example that does this, calculating the width but with the height code too:
var janela = 0;
function medeJanela(){
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
janela = x - 1000;
console.log(janela); // podes tirar isto depois, só para verificares
}
window.onresize = medeJanela;
In this way the variable is updated when the window is resized.
You just decrement 1000 of the window value every time you set the variable. For example:
var tamanhoJanela = getTamanhoJanela() - 1000;
// 1000 - 1000 = 0
// 997 - 1000 = -3
// 1003 - 1000 = 3
As I understand it would be like this:
var tamanho = 1000;
$(window).resize(function() {
var h = $(window).height();
tamanho += h > tamanho ? 1 : -1;
console.log(tamanho);
});