11540 sujets

JavaScript, DOM et API Web HTML5

Bonjour,

J'ai un soucis avec un système de newsticker. Lorsque je clique sur la flèche gauche c'est quand même la news d'après qui s'affiche et non celle d'avant.

En plus il y a un effet blanc qu'il n'y a pas quand on clique sur la flèche de droite. Bref je galère un peu, merci de votre aide Smiley smile

Voici mon fichier javascript newsticker.js

var Ticker = new Class({
    timer: null,
    initialize: function(el,options){
        this.setOptions(options);
        this.el = $(el);
        this.items = this.el.getElements('li');
        var w = 0;
        var h = 0;
         
        if(this.options.direction.toLowerCase()=='horizontal') {
            h = this.el.getSize().y;
                this.items.each(function(li,index) {
                w += li.getSize().x;
            });
        } else if(this.options.direction.toLowerCase()=='vertical') {
            w = this.el.getSize().x;
            this.items.each(function(li,index) {
                h += li.getSize().y;
            });
        }
        else {
            w = this.el.getSize().x;
            h = this.el.getSize().y;
            this.items.setStyles({
                position: 'absolute',
                top: 0,
                opacity: 0
            });
        }
         
        this.el.setStyles({
            position: 'absolute',
            top: 0,
            left: 0,
            width: w,
            height: h
        });
         
        if (this.options.direction.toLowerCase()=='fade')
        {
            this.fx = new Fx.Tween(this.items[0], {property:'opacity', duration [decu]this.options.speed/2), transition: this.options.transition}).set(1);
        }
        else
        {
            this.fx = new Fx.Morph(this.el, {duration:this.options.speed, transition: this.options.transition, onComplete:function() {
                var i = (this.current==0) ? this.items.length : this.current;
                this.items[i-1].injectInside(this.el);
                this.el.setStyles({
                    left:0,
                    top:0
                });
            }.bind(this)});
        }
        this.current = 0;
         
        if (this.options.delay > 0) {
            this.timer = this.next.bind(this).delay(this.options.delay+this.options.speed);
        } else {
            this.next();
        }
    },
     
    pause: function() {
        $clear(this.timer);
        this.timer = null;
    },
    resume: function() {
        if (this.timer == null) {
            this.next();
        }
    },
    next: function() {
        this.current++;
        if (this.current >= this.items.length) this.current = 0;
         
        if (this.options.direction.toLowerCase() == 'fade')
        {
            this.fx.start(1, 0).chain( (function() {
                this.fx = new Fx.Tween(this.items[this.current], {property:'opacity', duration [decu]this.options.speed/2), transition: this.options.transition}).start(0, 1).chain((function() {
                    if (this.options.delay == 0)
                        this.next();
                }).bind(this));
            }).bind(this));
        }
        else
        {
            var pos = this.items[this.current];
            this.fx.start({
                top: -pos.offsetTop,
                left: -pos.offsetLeft
            }).chain( (function() {
                // Update css classes
                this.fx.element.getElements('li').each( function(el, i, items)
                {
                    var cls = el.className;
                    cls = cls.replace(/odd|even|first|last/g, '').clean();
                     
                    // First element
                    if (i == 0)
                    {
                        cls += ' first';
                    }
         
                    // Last element
                    if (i >= (items.length-1))
                    {
                        cls += ' last';
                    }
                     
                    // Odd/even
                    cls += (i%2 == 0) ? ' even' : ' odd';
         
                    // Apply css class
                    el.className = cls.trim();
                });
                 
                if (this.options.delay == 0)
                    this.next();
            }).bind(this))
        }
         
        if (this.options.delay > 0) {
            this.timer = this.next.bind(this).delay(this.options.delay+this.options.speed);
        }
    },
    prev: function() {
            this.current++;
        if (this.current >= this.items.length) this.current = 0;
         
        if (this.options.direction.toLowerCase() == 'fade')
        {
            this.fx.start(1, 0).chain( (function() {
                this.fx = new Fx.Tween(this.items[this.current], {property:'opacity', duration [decu]this.options.speed/2), transition: this.options.transition}).start(0, 1).chain((function() {
                    if (this.options.delay == 0)
                        this.next();
                }).bind(this));
            }).bind(this));
        }
        else
        {
            var pos = this.items[this.current];
            this.fx.start({
                top: +pos.offsetTop,
                left: +pos.offsetLeft
            }).chain( (function() {
                // Update css classes
                this.fx.element.getElements('li').each( function(el, i, items)
                {
                    var cls = el.className;
                    cls = cls.replace(/odd|even|first|last/g, '').clean();
                     
                    // First element
                    if (i == 0)
                    {
                        cls += ' first';
                    }
         
                    // Last element
                    if (i >= (items.length-1))
                    {
                        cls += ' last';
                    }
                     
                    // Odd/even
                    cls += (i%2 == 0) ? ' even' : ' odd';
         
                    // Apply css class
                    el.className = cls.trim();
                });
                 
                if (this.options.delay == 0)
                    this.next();
            }).bind(this))
        }
         
        if (this.options.delay > 0) {
            this.timer = this.next.bind(this).delay(this.options.delay+this.options.speed);
        }
    }
});
 
Ticker.implement(new Options);


et le code de mon fichier .tpl correspondant

<div class="<?php echo $this->class; ?> block"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>>
<?php if ($this->headline): ?>
 
<<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>>
<?php endif; ?>
 
<?php if ($this->controls): ?>
 
<div id="controls-events">
 
   <div id="ticker_next_<?php echo $this->strId; ?>" class="ticker_next"><a><img src="css/arrow-right.png" width="22" height="28" alt="" /></a> </div>      
   <div id="ticker_prev_<?php echo $this->strId; ?>" class="ticker_prev"><a><img src="css/arrow-left.png" width="22" height="28" alt="" /></a> </div>   
</div>
 
<?php endif; ?>
<div class="ticker <?php echo $this->direction; ?>" style="height: <?php echo $this->height; ?>px">
   <ul class="ticker" id="ticker_<?php echo $this->strId; ?>" style="width: <?php echo $this->width; ?>px">
     
<?php foreach($this->articles as $article) echo $article; ?>
 
   </ul>
</div>
 
</div>
<?php if (count($this->articles) > 1): ?>
<!-- indexer::stop -->
<script type="text/javascript">
<!--//--><![CDATA[//><!--
window.addEvent('domready', function() {
   var ticker_<?php echo $this->strId; ?> = new Ticker('ticker_<?php echo $this->strId; ?>', {
      speed: <?php echo $this->speed; ?>,
      delay: <?php echo $this->delay; ?>,
      direction: '<?php echo $this->direction; ?>',
      transition: <?php echo $this->transition; ?>
   });
    
<?php if ($this->controls): ?>
    $$('#ticker_prev_<?php echo $this->strId; ?> a').addEvent('click', function() {
      ticker_<?php echo $this->strId; ?>.prev();
   });
    $$('#ticker_next_<?php echo $this->strId; ?> a').addEvent('click', function() {
      ticker_<?php echo $this->strId; ?>.next();
   });
       
<?php endif; ?>
 
    
});
 
//--><!]]>
</script>
<!-- indexer::continue -->
<?php endif; ?>


Et une démo en ligne ici

Merci d'avance !
Modifié par vince240986 (07 Feb 2013 - 11:57)