SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    large number of mootools Fx.Scroll

    is there a simpler way to do this

    http://demos.mootools.net/Fx.Scroll

    without having to add

    PHP Code:
    $('link1').addEvent('click', function(event) {
        
    event = new Event(event).stop();
        
    scroll.toElement('content1');
    }); 
    for every single scrollable items. it gets kinda cluttered once you have a lot of them, since im trying to integrate this into a dynamic application. someone told me to use foreach

    http://docs.mootools.net/Native/Array.js#Array.forEach

    but i have no idea how to do that

    any ideas?

    thanks

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Here are the links that the demo bar uses

    Code html4strict:
    <div id="demo-bar">
    	<a id="link1" href="#">The Blue Sky</a> | 
    	<a id="link2" href="#">Last Grass</a> |
    	<a id="link3" href="#">The Naked Tree</a> |
    	<a id="link4" href="#">The Lonesome Tree</a>
    </div>

    You can use $$('#demo-bar a') to target the links, and from there use the each method to loop through the collection

    Code javascript:
    $$('#demo-bar a').each(function(link, i) {
        $(link).addEvent('click', function(event) {
            event = new Event(event).stop();
            scroll.toElement('content' + (i + 1));
        });
    });
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •