0

I have a several scrollable menus at one page. There is a jQuery function which handles all those menus in "menu per menu" fashion, after I type this (hardcoded as it is) in a .js file:

    $(function(){
             Scrollable(".menu_wrapper1");
             Scrollable(".menu_wrapper2");

..and so on, all up to... 

       Scrollable(".menu_wrapper9");

HTML is simple as this..

    <div class="menu_wrapper1">Menu data</div>
    <div class="menu_wrapper2">Menu data 2</div>

and so on, up to 9 again.

Anyway, there is some possibility in near future for those menus to be more then 9 at one page or with different numbers at the end (like "menu_wrapper17") for example), so any chance for those different numbers of classes to be recognized and applied to this function by jQuery itself?

Something like Scrollable(".menu_wrapper[*]"); or similar I guess so function can be applied to any number?

Thx!

EDIT: Please, beware that every class has its own controls given by function.

4

3 回答 3

3

One way would be to add another class, such as scrollable_wrapper, and select that:

<div class="scrollable_wrapper menu_wrapper2">...</div>
Scrollable('.scrollable_wrapper');
于 2013-09-06T17:39:53.403 回答
2

Try this

$("div[class^='menu_wrapper']").each(function () {
Scrollable("."+$(this).attr('class'));
});

This will get each div whose classname startswith 'menuwarpper' and calls the Scrollable() with its class name as parameter.

Hope this helps,Thank you

于 2013-09-06T17:50:08.117 回答
0

Many solutions here:

1) Wrap all your menu_wrapper:

  <div id="big_menu_wrapper ">
    <div class="menu_wrapper1">Menu data</div>
    <div class="menu_wrapper2">Menu data 2</div>
  </div>

and select with Scrollable("#big_menu_wrapper > div")

2) Add the same class to all your menu_wrapper :

  <div class="menu_wrapper menu_wrapper1">Menu data</div>
  <div class="menu_wrapper menu_wrapper2">Menu data 2</div>

and select with Scrollable(".menu_wrapper")

3) Refactor your javascript function

于 2013-09-06T17:41:45.043 回答