Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

can

setinterval

Recommended Posts

entao tenho essa funcao em javascript so que ta dando erro creio que seja no setinterval mas nao conseguir arrumar da esse erro

 

this.setAlpha is not a function

 

quem souber que pode ser....

 

 

fadeOut : function(id, time) {

target = document.getElementById(id);

alpha = 100;

timer = (time*1000)/50;

var i = setInterval(

function() {

if (alpha <= 0)

clearInterval(i);

this.setAlpha(target, alpha);

alpha -= 2;

}, timer);

}

 

,

 

fadeIn : function(id, time) {

target = document.getElementById(id);

alpha = 0;

timer = (time*1000)/50;

var i = setInterval(

function() {

if (alpha >= 100)

clearInterval(i);

setAlpha(target, alpha);

alpha += 2;

}, timer);

}

 

,

 

setAlpha : function (target, alpha) {

target.style.filter = "alpha(opacity="+ alpha +")";

target.style.opacity = alpha/100;

}

Compartilhar este post


Link para o post
Compartilhar em outros sites

can,

para que isso funcione vai ter que fazer algumas alterações, só vou te mostrar o caminho, minha solução não é a melhor:

 

Substitua:

 

fadeOut : function(id, time) {
target = document.getElementById(id);
alpha = 100;
timer = (time*1000)/50;
var i = setInterval(
function() {
if (alpha <= 0)
clearInterval(i);
this.setAlpha(target, alpha);
alpha -= 2;
}, timer);
}

Por:

 

fadeOut : function(id, time) {

 

target = document.getElementById(id);
	alpha = 100;
	timer = (time*1000)/50;
	
	/*codigo alterado*/
	var self = this;
	var func = function() {
		if (alpha <= 0)
		clearInterval(i);
		this.setAlpha(target, alpha);
		alpha -= 2;
	}
	var i = setInterval(function(){func.call(self)} , timer);
	/*codigo alterado*/
}

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.