简体   繁体   English

淡入淡出Divs

[英]Fade in, Fade out Divs

I'm trying to build a webpage that is essentially one page, but with four 'hidden' divs that will fade in and out of visibility when you click on menu buttons along the bottom. 我正在尝试构建一个基本上是一页的网页,但是具有四个“隐藏”的div,当您单击底部的菜单按钮时,它们会淡入和淡出可见性。

I would like to put a 'close' button at the top of each of these divs so you can 'close' that div - but it would be great if the div still faded out on its own when a new menu item is clicked. 我想在每个div的顶部放置一个“关闭”按钮,以便您可以“关闭”该div-但是,如果在单击新菜单项时div仍然自行淡出,那就太好了。 So far I've created the div boxes and the links using css and html, but I'm an absolute newbie when it comes to javascript. 到目前为止,我已经使用css和html创建了div框和链接,但是当涉及到javascript时,我绝对是新手。 Here's the code I have so far 这是我到目前为止的代码

HTML: HTML:

<div class="menu">
    <a class="portfolio" href="http://www.google.com"> Portfolio </a> | <a  class="aboutme" href="http://www.google.com"> About Me </a> | <a class="education" href="http://www.google.com"> Education</a> | <a class="contact" href="http://www.google.com"> Contact</a>
</div>
<div>`

(NOTE: I only put google as the link target because I didn't know what else to put). (注意:我只将google用作链接目标,因为我不知道还要输入什么)。

CSS: CSS:

.aboutmewindow
{
    width:583px;
    height:557px;
    border-bottom-style:dashed;
    position:absolute;
    top:0px;
    z-index:2;  
}

.portfoliowindow
{
    width:583px;
    height:557px;
    border-bottom-style:dashed;
    position:absolute;
    top:0px;
    z-index:2;  
}

.educationwindow
{
    width:583px;
    height:557px;
    border-bottom-style:dashed;
    position:absolute;
    top:0px;
    z-index:2;  
}

.contactwindow
{
    width:583px;
    height:557px;
    border-bottom-style:dashed;
    position:absolute;
    top:0px;
    z-index:2;  
}`

I've tried writing a little bit of the javascript on my own, but it's seriously out of my depth at this point. 我已经尝试过自己编写一些javascript,但是到现在为止,这已经超出了我的理解范围。 I'm going to keep going through tutorials though, so hopefully I'll get the hang of it. 不过,我将继续阅读教程,所以希望我能掌握其中的内容。

Anyone have any suggestions? 有人有什么建议吗? Or good tutorials? 还是好的教程?

Thanks! 谢谢!

you can try this its a simple example but without all your markup and code you can get the idea .. requires jQuery 您可以尝试这是一个简单的示例,但是没有所有标记和代码,您可以明白这个主意..需要jQuery

http://jsfiddle.net/YnzRV/9/ http://jsfiddle.net/YnzRV/9/

$(function(){

    $("#main > .box").not(":first").hide();

    $(".menu").on("click", "a", function(){

        var $this = $(this),
            dataBox = $this.data("box");

        $("#main > .box").hide();
        $("."+dataBox).fadeIn(400);

        return false;
    });

});

if you check the jsfiddle you will see how i added data attributes that get passed through the click handler to tell it which div to show using the data attributes 如果您检查jsfiddle,您将看到我如何添加通过点击处理程序传递的数据属性,以告诉该用户使用数据属性显示哪个div

You can use fadeIn() or fadeOut() . 您可以使用fadeIn()fadeOut()

Use it like this: 像这样使用它:

$('selector').fadeIn(); // you can use time in ms, inside ()

Similarly, you can use fadeOut too. 同样,您也可以使用fadeOut But keep in mind, that you have the latest version of jQuery linked to your web page. 但是请记住,您已将最新版本的jQuery链接到您的网页。

Links: 链接:

http://jquery.com http://jquery.com

This is a slightly outdated (August, 2012) tutorial showing you the HTML, CSS, and JavaScript required to fade elements in, fade them out, and fade them to a specific opacity. 这是一个过时的教程(2012年8月),向您显示了淡入,淡出和将它们淡化为特定不透明度所需的HTML,CSS和JavaScript。

http://www.mkyong.com/jquery/jquery-fadein-fadeout-and-fadeto-example/ http://www.mkyong.com/jquery/jquery-fadein-fadeout-and-fadeto-example/

You're essentially trying to learn about the following: 您实质上是在尝试了解以下内容:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM