te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - How can i make a list menu "collapsible"? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can i make a list menu "collapsible"? - Stack Overflow

programmeradmin4浏览0评论

i have a menu with 4 main items and each one having 3 to 5 sub items.

<ul id="navigation">
    <li><a>Diagonóstico</a>

    </li>
    <li class="sub"><a href="javascript:void(0);" class="sub_di1"> › Grátis (na pra de qualquer serviço) </a>

    </li>
    <li><a>Hardware</a> 
    </li>
    <li class="sub"><a href="javascript:void(0);" class="sub_ha1"> › Instalação/Configuração de Componentes</a>

Please check the full code.

As you can see in the jsFiddle, all menu items, when clicked show some text in another div. I put that there just in case it was be needed for further javascript help. What i want is to have all .sub menus collapsed and when i mouseover one of the main ones, it expands the corresponding .sub items so user can see. Thanks!

EDIT:

I managed to get a nice tutorial in one of the ments and came up with THIS!

What i need now is a way to show ALL the .sub menus from the corresponding .main menus instead of only the first ones.

i have a menu with 4 main items and each one having 3 to 5 sub items.

<ul id="navigation">
    <li><a>Diagonóstico</a>

    </li>
    <li class="sub"><a href="javascript:void(0);" class="sub_di1"> › Grátis (na pra de qualquer serviço) </a>

    </li>
    <li><a>Hardware</a> 
    </li>
    <li class="sub"><a href="javascript:void(0);" class="sub_ha1"> › Instalação/Configuração de Componentes</a>

Please check the full code.

As you can see in the jsFiddle, all menu items, when clicked show some text in another div. I put that there just in case it was be needed for further javascript help. What i want is to have all .sub menus collapsed and when i mouseover one of the main ones, it expands the corresponding .sub items so user can see. Thanks!

EDIT:

I managed to get a nice tutorial in one of the ments and came up with THIS!

What i need now is a way to show ALL the .sub menus from the corresponding .main menus instead of only the first ones.

Share Improve this question edited Apr 14, 2013 at 23:23 Bruno Charters asked Apr 14, 2013 at 22:00 Bruno ChartersBruno Charters 4942 gold badges6 silver badges15 bronze badges 7
  • 2 youtube./watch?v=qBh_lMO_SDM check this out! – auicsc Commented Apr 14, 2013 at 22:11
  • 1 Are you specifically looking for a javascript solution? You can acplish this with CSS and some adjustment to your HTML if you like. – Dave Commented Apr 14, 2013 at 22:52
  • @dentaku i managed to get a nice script to work from the video above, i just need a bit tweak and i'll be good to go. (: – Bruno Charters Commented Apr 14, 2013 at 23:02
  • @auicsc I used that tutorial and came up with something really neat, altho still need some tweaks. – Bruno Charters Commented Apr 14, 2013 at 23:08
  • @BrunoCharters Glad to hear it. If you're ever interested in a straight CSS solution, look into the :hover psuedo-class. :) – Dave Commented Apr 14, 2013 at 23:12
 |  Show 2 more ments

2 Answers 2

Reset to default 10

Using only HTML and CSS.

HTML

<ul id="menu">
    <li><a href="SOME_LINK">Some menu without sub-menu</a></li>
    <li><a href="SOME_LINK2">Some menu without sub-menu 2 </a></li>
    <li>Some menu WITH sub-menu
        <ul>
            <li><a href="SOME_LINK">Some sub-menu</a></li>
            <li><a href="SOME_LINK">Some sub-menu 2</a></li>
        </ul>
    </li>
    <li><a href="SOME_LINK3">Some menu without sub-menu 3</a></li>
</ul>

CSS

ul>li>ul{display:none}
ul>li:hover>ul, ul>li:selected>ul{display:block}

JS (jQuery) to OPEN all submenus

$('#menu li>ul').parent().addClass('selected');

JS without Jquery

var menus = document.getElementById('menu').getElementsByTagName('li') 
for(var row in menus){
     if(typeof menus[row] == 'object' && menus[row].getElementsByTagName('ul').length > 0){
         menus[row].getElementsByTagName('ul')[0].className = 'selected';
     }
}

My solution is similar to the one mentioned in the question edit, but an already open list item does not re-open when beging clicked: http://jsfiddle/g5oc0uoq/

$('.content').hide();
$('.listelement').on('click', function(){
  if(!($(this).children('.content').is(':visible'))){
    $('.content').slideUp();
    $(this).children('.content').slideDown();
  } else {
    $('.content').slideUp();
  }
});

show() and hide() can be used instead of slideUp() and slideDown() if you have performance issues.

发布评论

评论列表(0)

  1. 暂无评论