IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

maj contenu webticker vitesse erronée


Sujet :

JavaScript

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    182
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 182
    Points : 178
    Points
    178
    Par défaut maj contenu webticker vitesse erronée
    Bonjour à tous!

    Je voudrais votre avis car j'ai créé un bandeau déroulant à excès de vitesse!
    en fait le script de base de mioplanet marche très bien.
    sauf quand on modifie le contenu qui défile en couplant à de l'ajax visiblement...

    voici mon webticker modif:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    // WebTicker by Mioplanet
    // www.mioplanet.com
     
    TICKER_CONTENT = $('TICKER').innerHTML;
     
    TICKER_RIGHTTOLEFT = false;
    TICKER_SPEED = 2;
    TICKER_STYLE = "font-family:Arial; font-size:12px; color:#444444";
    TICKER_PAUSED = false;
     
    ticker_start();
     
    function ticker_start() {
    	window.setTimeout("calcul2()",10000);
    	var tickerSupported = false;
    	TICKER_WIDTH = $('TICKER').style.width;
    	var img = "<img src=ticker_space.gif width="+TICKER_WIDTH+" height=0>";
     
    	// Firefox
    	if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1) {
    		$('TICKER').innerHTML = "<TABLE  cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'>&nbsp;</SPAN>"+img+"</TD></TR></TABLE>";
    		tickerSupported = true;
    	}
    	// IE
    	if (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1) {
    		$('TICKER').innerHTML = "<DIV nowrap='nowrap' style='width:100%;'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'></SPAN>"+img+"</DIV>";
    		tickerSupported = true;
    	}
    	if(!tickerSupported) $('TICKER').outerHTML = ""; else {
    		$('TICKER').scrollLeft = TICKER_RIGHTTOLEFT ? $('TICKER').scrollWidth - $('TICKER').offsetWidth : 0;
    		document.getElementById("TICKER_BODY").innerHTML = TICKER_CONTENT;
    		$('TICKER').style.display="block";
    		TICKER_tick();
    	}
    }
     
    function TICKER_tick() {
    	if(!TICKER_PAUSED) $('TICKER').scrollLeft += TICKER_SPEED * (TICKER_RIGHTTOLEFT ? -1 : 1);
    	if(TICKER_RIGHTTOLEFT && $('TICKER').scrollLeft <= 0) $('TICKER').scrollLeft = $('TICKER').scrollWidth - $('TICKER').offsetWidth;
    	if(!TICKER_RIGHTTOLEFT && $('TICKER').scrollLeft >= $('TICKER').scrollWidth - $('TICKER').offsetWidth) $('TICKER').scrollLeft = 0;
    	window.setTimeout("TICKER_tick()", 30);
    }
    function calcul2()
    {
    $('calculatrice2').request({
    		onComplete: function(transport)
    		{
    			var err2="";
    			err2 =(transport.responseText);
    			if (err2!="")
    			{
    				ticker_maj(err2);
    			}
    		}
    	})
    }
    function ticker_maj(cont){
    var plop=cont;
    TICKER_WIDTH = $('TICKER').style.width;
    TICKER_CONTENT=plop;
    TICKER_SPEED = 2;
    ticker_start();
    }
    Concrètement à chaque mise à jour du bandeau: la vitesse de défilement accélère... et je ne parviens pas à savoir pourquoi ...

  2. #2
    Expert confirmé
    Avatar de le_chomeur
    Profil pro
    Développeur informatique
    Inscrit en
    Février 2006
    Messages
    3 653
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 3 653
    Points : 4 835
    Points
    4 835
    Par défaut
    tu appel ta méthode :

    window.setTimeout("calcul2()",10000);

    sans jamais tuer le timer , ce qui fait qu'au bout d'un moment tu te retrouve avec plusieurs intances ... ( ta méthode est appelé plusieurs fois si tu préfères )

  3. #3
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 640
    Points : 66 663
    Points
    66 663
    Billets dans le blog
    1
    Par défaut
    oui un petit clearTimeout en ayant pris le soin d'attribuer l'instance à une variable globale afin de pouvoir la "tuer" avant d'en lancer une autre

  4. #4
    Membre habitué
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    182
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 182
    Points : 178
    Points
    178
    Par défaut
    merci pour vos réponses!
    j'ai finalement trouvé la solution en perceverant. si ça peut servir à quelqu'un:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    TICKER_CONTENT = $('TICKER').innerHTML;
     
    TICKER_RIGHTTOLEFT = false;
    TICKER_SPEED = 2;
    TICKER_STYLE = "font-family:Arial; font-size:12px; color:#444444";
    TICKER_PAUSED = false;
    var a=0;
    window.setInterval("calcul2()",5000);
     
    ticker_start();
     
    function ticker_start() {
    	var tickerSupported = false;
    	TICKER_WIDTH = $('TICKER').style.width;
    	var img = "<img src=ticker_space.gif width="+TICKER_WIDTH+" height=0>";
     
    	// Firefox
    	if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1) {
    		$('TICKER').innerHTML = "<TABLE  cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'>&nbsp;</SPAN>"+img+"</TD></TR></TABLE>";
    		tickerSupported = true;
    	}
    	// IE
    	if (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1) {
    		$('TICKER').innerHTML = "<DIV nowrap='nowrap' style='width:100%;'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'></SPAN>"+img+"</DIV>";
    		tickerSupported = true;
    	}
    	if(!tickerSupported) $('TICKER').outerHTML = ""; else {
    		$('TICKER').scrollLeft = TICKER_RIGHTTOLEFT ? $('TICKER').scrollWidth - $('TICKER').offsetWidth : 0;
    		document.getElementById("TICKER_BODY").innerHTML = TICKER_CONTENT;
    		$('TICKER').style.display="block";
    		TICKER_tick();
    	}
    }
    function TICKER_tick() {
    	if(!TICKER_PAUSED) $('TICKER').scrollLeft += TICKER_SPEED * (TICKER_RIGHTTOLEFT ? -1 : 1);
    	if(TICKER_RIGHTTOLEFT && $('TICKER').scrollLeft <= 0) $('TICKER').scrollLeft = $('TICKER').scrollWidth - $('TICKER').offsetWidth;
    	if(!TICKER_RIGHTTOLEFT && $('TICKER').scrollLeft >= $('TICKER').scrollWidth - $('TICKER').offsetWidth) $('TICKER').scrollLeft = 0;
    if(a=="0")
    {
    		window.setInterval("TICKER_tick()", 30);
    		a=1;
    }
    }
    function calcul2()
    {
    $('calculatrice2').request({
    		onComplete: function(transport)
    		{
    			var err2="";
    			err2 =(transport.responseText);
    			if (err2!="")
    			{
    				ticker_maj(err2);
    			}
    		}
    	})
    }
    function ticker_maj(cont){
    var plop=cont;
    TICKER_WIDTH = $('TICKER').style.width;
    TICKER_CONTENT=plop;
    ticker_start();
    }
    merci à tous !

  5. #5
    Expert confirmé
    Avatar de le_chomeur
    Profil pro
    Développeur informatique
    Inscrit en
    Février 2006
    Messages
    3 653
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 3 653
    Points : 4 835
    Points
    4 835
    Par défaut
    mouai pas la meilleur solution ...
    mais c'est comme tu le sens

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    182
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 182
    Points : 178
    Points
    178
    Par défaut
    sachant que la mise à jour de contenu va être faite assez souvent, ça évitera des lancements/ arrets a tout bout de champ, sachant que le bandeau ne doit pas s'arreter

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 5
    Dernier message: 30/03/2007, 18h26

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo