jQuery show()没有显示幻灯片效果

时间:2012-12-21 21:47:44

标签: javascript jquery html css jquery-ui

我想使用幻灯片效果隐藏和显示文章元素。当我加载页面并单击主页时,如果文章在屏幕上可见,我写的js将它平滑地保存并且没有任何问题。但是当我点击关于我们链接,它立即显示文章没有幻灯片效果。

这是显示和隐藏代码+ html +消失的CSS:

HTML:

<nav>
    <ul class="sf-menu sf-vertical">
        <li><a href=# onclick=home()>Home</a></li>
        <li><a href=#about onclick=about()>About Us</a></li>
        <li><a href=#>Cuisines</a>
            <ul>
                <li><a href=#starters>Starters</a></li>
                <li><a href=#>Main Dishes</a></li>
                <li><a href=#>Desserts</a></li>
                <li><a href=#>Mezes</a></li>
            </ul>
        </li>
        <li><a href=#>Wine List</a></li>
        <li><a href=#gallery>Gallery</a></li>
        <li><a href=#contacts>Contacts</a></li>
    </ul>
</nav>

<article class=vanished id=about>
    <h1>About Us</h1>
    <div class="main-wrapper scroll">
        <div class="wrapper clearfix">
            <img src=img/bazar-place.png alt=bazar-place width=222 height=150 class=about-img>
            <h4>Our Restaurant</h4>
            <p>Bazar is a restaurant located between the districts Haga and Vasastaden in Gothenburg with a focus on Turkish and Persian food of the best quality that creates opportunities for an exciting mix all the way, from appetizer to dessert.</p>
        </div>
        <div class="wrapper clearfix">
            <img src=img/belly.jpg alt=belly-dancing width=222 height=167 class=about-img id=belly>
            <h4>Events</h4>
            <p>Every Saturday from 21, we have Belly dancing at Bazar.</p>
        </div>
        <div class="wrapper clearfix">
            <img src=img/food.jpg alt=food-services width=222 height=167 class=about-img id=food>
            <h4>Food Services</h4>
            <p>Taste our famous pasta dish to the human price of 69 :- We offer 10% discount for take-away at our entire menu.</p>
            <p>At lunchtime you can choose from three Turkish pasta dishes or among two or three different main dishes. Ask about vegetarian options! Drinking, salad and coffee / tea included. Lunch can also be picked up.</p>
        </div>
        <div class="wrapper last clearfix">
            <img src=img/extra.jpg alt=extra-services width=222 height=167 class=about-img id=extra>
            <h4>Extra Services</h4>
            <p>We can help with everything from after work, kick-off to the birthday called with food and drink that lasts all night. Do you want more entertainment we can arrange live music and belly dancing.</p>
        </div>
    </div>
</article>

使用Javascript:

function home(){

    if ($(".active") == [])
    {
        return ;
    }
    else
    {
        var active = $(".active");
        active.css("display","inline-block");
        active.hide("slide",{direction:"left"},700);
        active.attr("class","vanished");

    }
}
function about(){
    if ($(".active") == [])
    {
        var hidden = $("#about");
        hidden.css("display","inline-block");
        hidden.show("slide",{direction : "right"},700);
        hidden.attr("class","active");
    }
    else
    {
        if ($("#about").attr("class") == "active")
        {
            return ;
        }
        else
        {
            var active = $(".active");
            active.css("display","inline-block");
            active.hide("slide",{direction:"left"},700);
            active.attr("class","vanished");
            var hidden = $("#about");
            hidden.css("display","inline-block");
            hidden.show("slide",{direction : "right"},700);
            hidden.attr("class","active");
        }

    }
}

CSS:

.vanished{
    display: none;
}

1 个答案:

答案 0 :(得分:1)

这是在hide / show之前:所以它在那时显示为一个块。

 hidden.css("display","inline-block");

我会把CSS放入其中,然后删除这些行。