Par ce samedi pluvieux, il ne reste plus que ca a faire
Merci nod__ de ta participation.
Je ne connaissait pas le coup de :
1 2 3 4 5
| function redim (param) {alert (param);}
obj.Tick = redim;
// et c'est immédiat
obj.Tick("mon paramètre"); // affiche : mon paramètre |
Effectivement si j'ai besoin de redim dans tout mes objet, à ce moment là, je ferai un classe fille spécifique qui hériterait de Timer et que j'appelerai RedimVisuel et où j'ajouterai la méthode redim. Hop allons voir l'héritage de classe en JS ;
De plus, j'ai eu un problème avec la propriété Enable :
si j'écris
if(obj2.Enable==true){obj2.Stop();};obj.Start(400);
je recupere bien mes etats true inversement false.
mais si je fait
if(obj2.Enable){obj2.Stop();};obj.Start(400);
la condition obj2.Enable est toujours vrai.
Est ce que c'était ce que tu voulais dire ?
J'essaie de compliquer les choses en demandant à la sortie de ma souris que l'image rapetisse jusqu'à une certaine largeur.
Et qu'on puisse tout recommencer.
Voici le code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
<script language="JavaScript">
// Declaring class "Timer"
var Timer = function()
{
// Property: Frequency of elapse event of the timer in millisecond
this.Interval = 1000;
// Property: Whether the timer is enable or not
this.Enable = new Boolean(false);
// Event: Timer tick
this.Tick;
// Member variable: Hold interval id of the timer
var timerId = 0;
// Member variable: Hold instance of this class
var thisObject;
// Function: Start the timer
this.Start = function(variables)
{
this.Enable = new Boolean(true);
thisObject = this;
if (thisObject.Enable)
{
thisObject.timerId = setInterval(
function()
{
thisObject.Tick(variables);
}, thisObject.Interval);
}
};
// Function: Stops the timer
this.Stop = function()
{
thisObject.Enable = new Boolean(false);
clearInterval(thisObject.timerId);
};
};
function redim(widthMax)
{
if(document.getElementById('imagetest').width<widthMax)
document.getElementById('imagetest').width=document.getElementById('imagetest').width+1;
}
function redimMoins(widthMin)
{
if(document.getElementById('imagetest').width>widthMin)
document.getElementById('imagetest').width=document.getElementById('imagetest').width-1;
}
var obj = new Timer();
obj.Interval = 100;
obj.Tick = redim;
var obj2 = new Timer();
obj2.Interval = 100;
obj2.Tick = redimMoins;
</script>
<img src="00056.jpg" id="imagetest" onMouseOver="if(obj2.Enable==true){obj2.Stop();};obj.Start(400);" onMouseOut="obj.Stop();obj2.Start(20);" /> |
Partager