javascript - jQuery show() 不显示幻灯片效果

标签 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;
}

最佳答案

这是在隐藏/显示之前:所以它在那个时候显示为一个 block 。

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

我会为此添加 CSS,然后删除这些行。

关于javascript - jQuery show() 不显示幻灯片效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13997631/

相关文章:

jquery - 如何通过向导使用 asp.net mvc 3 不引人注目的 javascript 验证?

jquery - 更改页面滚动上的事件菜单项?

html - 使用 Bootstrap 时获取 'data-wssurvey'

javascript - Highcharts 不会导出创建后添加的自定义 SVG 元素

javascript - 函数未运行/未正确调用

javascript - 使用 Socket.IO,在发送 JavaScript 事件时防止客户端劫持 - 使用 SignalR?

javascript - 在全局范围内声明的变量未被函数识别

javascript - 通过单击行用行数据预填充表单字段

jquery - 在 JQuery qtip2 弹出窗口中显示 HTML 部分

html - 如何更改下拉菜单(选择)中第一个选项标签的字体大小?