Try adding the event outside of $('newStep').addEvent('click', function
(e) {

I dont show where your inserting this:
$('link'+ clicks)).addEvent('click', function(event) {
        event = new Event(event).stop();
        scroll.toElement('content'+ clicks));
});

so if its inside the newStep event, it might be trying to fire before
the element is even built.

also, your not stoppping the normal click function while building your
myAnchor element
'click': function(){
                                scroll.toElement('content'+ clicks);
                         }

On Nov 16, 5:46 am, ashi <[EMAIL PROTECTED]> wrote:
> why use id? use element reference instead
>
> scroll.toElement(newDiv)
>
> and i think there must be some other solution better than this
>
> On Nov 15, 7:14 pm, NicoSalto <[EMAIL PROTECTED]> wrote:
>
> > Hello everybody,
> > iam a newbie in mootools programming.
>
> > Iam trying to build a scroll wirth link to auto add new divs in the
> > scroll. Its working except when i built a new link, i cannot add a new
> > event on it ...
>
> > There is my code:
>
> > window.addEvent('domready', function() {
>
> >         var scroll = new Fx.Scroll('demo-wrapper', {
> >                                 wait: false,
> >                                 duration: 1500,
> >                                 offset: {'x': 0, 'y': 0},
> >                                 transition: Fx.Transitions.Quad.easeInOut
> >                         });
>
> >         var clicks=2; //counter to keep track of clicks
> >         $('newStep').addEvent('click', function(e) {
>
> >                 new Event(e).stop;
>
> >                         var newDivText="STEP "+ clicks+" / ";
> >                         var step_title;
> >                         step_title="step_title"+ clicks;
> >                         var content;
> >                         content="content"+ clicks;
> >                         var oldcontent;
> >                         var oldclicks = clicks - 1;
> >                         oldcontent="content"+ oldclicks;
>
> >                         //Add a new div in the scroll div
> >                         var newDiv=new Element('div', {
> >                                 'id': content,
> >                                 'class': 'scrolling-content'
> >                         }).setText(newDivText).injectAfter(oldcontent);
>
> >                         //Add a new link to command the scroll
> >                         var myAnchor = new Element('a', {
> >                         'href': '#content'+ clicks,
> >                                 'id': 'link'+ clicks,
> >                         'events': {
> >                         'click': function(){
> >                                 scroll.toElement('content'+ clicks);
> >                          }
> >                                  }
> >                         }).setText(newDivText).inject('demo-bar', 'top');
>
> >                         clicks++;
> >         });});
>
> > </script>
>
> > <body>
> > <div id="conteneur"> <a href="#" id="newStep">Add a new Step >></a>
> >   <div id="demo-bar"> </div>
> >   <div id="demo-wrapper">
> >     <div id="demo-inner">
> >       <div id="content1" class="scrolling-content">
> >         <h1>The Blue Sky</h1>
> >       </div>
> >     </div>
> >   </div>
> > </div>
> > </body>
>
> > The problem is here :
> > scroll.toElement('content'+ clicks);
> > I tried to add an event to the link with this code without result
>
> > $('link'+ clicks)).addEvent('click', function(event) {
> >         event = new Event(event).stop();
> >         scroll.toElement('content'+ clicks));
>
> > });
>
> > thanks in advance
>
> > NC

Reply via email to