jQuery淡入/淡出onclick for li

时间:2012-05-12 20:47:36

标签: jquery html css html5

我正在设置服务部分。每个部分都带有它自己的li的集合。我想把李隐藏起来,显示:无;并点亮onclick /淡出onclick。使用我当前的标记和样式编写此函数的js时遇到问题。

html -

<div id="small-container" class="services">
                    <nav id="services-sections">
                        <a class="active" href="#/one" id="nav-one">One</a>
                        <a href="#/two" id="nav-two">Two</a>
                        <a href="#/three" id="nav-three">Three</a>
                        <a href="#/four" id="nav-four">Four</a>
                        <a href="#/five" id="nav-five">Five</a>
                    </nav>
                    <article id="section-one" class="services-content">
                        <ul class="services">
                            <li class="service-item">One - one </li>
                            <li class="service-item">One - two </li>
                            <li class="service-item">One - three </li>
                        </ul>
                    </article>
                    <article id="section-two" class="services-content">
                        <ul class="services">
                            <li class="service-item">Two - one </li>
                            <li class="service-item">Two - two </li>
                            <li class="service-item">Two - three </li>
                        </ul>
                    </article>
                    <article id="section-three" class="services-content">
                        <ul class="services">
                            <li class="service-item">Three - one </li>
                            <li class="service-item">Three - two </li>
                            <li class="service-item">Three - three </li>
                        </ul>
                    </article>
                    <article id="section-four" class="services-content">
                        <ul class="services">
                            <li class="service-item">Four - one </li>
                            <li class="service-item">Four - two </li>
                            <li class="service-item">Four - three </li>
                        </ul>
                    </article>
                    <article id="section-five" class="services-content">
                        <ul class="services">
                            <li class="service-item">Five - one </li>
                            <li class="service-item">Five - two </li>
                            <li class="service-item">Five - three</li>
                        </ul>
                    </article>
                </div>

css -

#small-container { float: left; width: 240px; color: #000; font-family: Arial, Helvetica, sans-serif; }
        #small-container.services { width: 350px; }
        #services-sections a { text-decoration: none;  text-transform: none; font-weight: bold; font-size: 1em; margin-right: 12px; margin-bottom: 10px; display: inline-block; color: #222; }
        #services-sections a:hover, #services-sections a.active { color: #AAA; }
        .services-content { display: ; position: relative;  }
        .services-content.active { display: inline-block; }
        .services { list-style-position: inside; list-style: none; }
        .services { *list-style: none; }
        .services.active {}
        .service-item { text-indent: -15px; padding-left: 6px; margin-bottom: 12px; font-size: 12px; cursor: default; }
        .ie8 .service-item { text-indent: -22px; }
        .ie7 .service-item { text-indent: -18px; padding-left: 20px; }  

任何帮助将不胜感激。 提前谢谢!

2 个答案:

答案 0 :(得分:3)

$("#services-sections > a").click(function () {
    $("#section-" + this.id.split("-")[1]).fadeToggle();
});

Demo.

答案 1 :(得分:1)

$('ul.services li').click(function(){
   $(this).fadeOut(function(){$(this).fadeIn();});
})