2014-12-13 176 views
0

我有一個菜單運行不正常。當我想要在菜單內出現的div在動畫變小之後隱藏()。它不會僅僅消失一秒,然後重新出現在菜單之外。我似乎無法弄清楚爲什麼。菜單部分被稱爲.title。謝謝您的幫助。如果語句故障,jQuery菜單

jQuery的

var tag = document.createElement('script'); 

tag.src = "//www.youtube.com/iframe_api"; 
var firstScriptTag = document.getElementsByTagName('script')[0]; 
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 

var player; 

function onYouTubeIframeAPIReady() { 
    player = new YT.Player('video', { 
     events: { 
      'onReady': onPlayerReady 
     } 
    }); 
} 

function onPlayerReady() { 
    player.playVideo(); 
    // Mute! 
    player.mute(); 
} 

$(".rotate").textrotator({ 
    animation: "flip", 
    speed: 4000 
}); 

$(document).ready(function() { 
    var menuBtn = $(".menuBtn"); 
    var title  = $(".title"); 
    var nav  = $("nav"); 
    var navLi  = $("nav").find("li"); 

    var slideDown = function(){ 
     if (!title.hasClass("title-element")) { 
      title.addClass("title-element", 500); 
     }; 
    }; 

    var scrollTo = function(place) { 
     $(place).animatescroll({ 
      scrollSpeed: 1000, 
      padding: 10 
     }); 
    }; 

    var close = function(id) { 
     if ($("#" + id).is(":visible")) { 
      $("#" + id).hide(); 
      title.delay(250).removeClass("title-element", 500); 
      scrollTo('#top'); 
     } 
    }; 

    var fadeInElement = function(id) {  
     $('#' + id).delay(500).fadeIn(250); 
     scrollTo('.title'); 
    }; 

    menuBtn.click(function(){ 
     title.toggleClass("title-menu", 500); 
     if (nav.is(":visible")) { 
      nav.hide(); 
     } else { 
      nav.delay(500).fadeIn(250); 
     } 
     $('#about, #works, #contact').filter(":visible").hide(); 
     title.delay(250).removeClass("title-element", 500); 
     scrollTo('#top'); 
    }); 

//ABOUT------------------------------------------------- 
    $(".about").click(function(){ 
     slideDown(); 
     $('#works, #contact').filter(":visible").hide(); 
     fadeInElement("about"); 
     close("about"); 
    }); 
//WORKS------------------------------------------------- 
    $(".works").click(function(){ 
     slideDown(); 
     $('#about, #contact').filter(":visible").hide(); 
     fadeInElement("works"); 
     close("works"); 
    }); 
//CONTACT----------------------------------------------- 
    $(".contact").click(function(){ 
     slideDown(); 
     $('#about, #works').filter(":visible").hide(); 
     fadeInElement("contact"); 
     close("contact"); 
    }); 
//------------------------------------------------------ 
}); 

CSS

* { 
    margin: 0; 
    padding: 0; 
} 

a:link, 
a:hover, 
a:active, 
a:visited { 
    text-decoration: none; 
    cursor: pointer; 
} 

body { 
    height: 100%; 
    width: 100%; 
    background: #000; 
    overflow: hidden; 
} 

.logo-bg { 
    z-index: 50; 
    position: relative; 
    top: -230px; 
    width: 802px; 
    height: 803px; 
    margin: 0 auto; 
    display: block; 
} 

#video { 
    position: absolute; 
    top: -40px; 
    left: 50%; 
    margin-left: -360px; 
    width: 720px; 
    height: 500px; 
} 

.title { 
    background: url(../img/paper.jpg); 
    z-index: 51; 
    position: relative; 
    top: -470px; 
    left: 50%; 
    margin-left: -344px; 
    width: 695px; 
    height: 37px; 
    padding: 10px 0; 
    border: 1px solid #fff; 

    -webkit-border-radius: 5px; 
    -moz-border-radius: 5px; 
    border-radius:   5px; 

    -webkit-box-shadow: inset 0px 0px 7px #000; 
    -moz-box-shadow: inset 0px 0px 7px #000; 
    box-shadow:   inset 0px 0px 7px #000; 
} 

.title-menu { 
    height: 80px; 
} 

.title-element { 
    height: 627px; 
} 

.title p { 
    font-family: 'Montserrat', sans-serif; 
    font-size: 30px; 
    font-weight: bolder; 
    color: #F3FFFF; 
    text-align: center; 
    text-shadow:0px 0px 0 rgb(210,210,210),-1px 0px 0 rgb(165,165,165),-2px 0px 0 rgb(120,120,120), -3px 0px 0 rgb(75,75,75),-4px 0px 3px rgba(0,0,0,1),-4px 0px 1px rgba(0,0,0,0.5),0px 0px 3px rgba(0,0,0,.2); 
} 

.menuBtn { 
    z-index: 99; 
    position: absolute; 
    top: 328px; 
    left: 50%; 
    margin-left: 290px; 
    cursor: pointer; 

    -webkit-transition: all 250ms ease; 
    -moz-transition: all 250ms ease; 
    -ms-transition:  all 250ms ease; 
    -o-transition:  all 250ms ease; 
    transition:   all 250ms ease; 

    -webkit-filter: drop-shadow(-2px 1px 1px #777); 
    filter: drop-shadow(-2px 1px 1px #777); 
} 

.menuBtn:active { 
    margin-left: 288px; 
    -webkit-filter: none; 
    filter: none; 
} 

nav { 
    margin-top: 10px; 
    display: none; 
} 

hr { 
    opacity: .3; 
    border: 0; 
    height: 1px; 
    background-image: -webkit-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,1), rgba(0,0,0,0)); 
    background-image: -moz-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,1), rgba(0,0,0,0)); 
    background-image:  -ms-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,1), rgba(0,0,0,0)); 
    background-image:  -o-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,1), rgba(0,0,0,0)); 
} 

nav li { 
    font-family: 'Exo 2', sans-serif; 
    color: #eee; 
    float: left; 
    text-align: center; 
    display: inline-block; 
    width: 153px; 
    margin: 10px; 
    cursor: pointer; 
    text-shadow: -1px 0px 1px #000; 

    -webkit-transition: all 250ms ease; 
    -moz-transition: all 250ms ease; 
    -ms-transition:  all 250ms ease; 
    -o-transition:  all 250ms ease; 
    transition:   all 250ms ease; 
} 

nav li:hover { 
    text-shadow: none; 
    color: #444; 
} 

#about, 
#works, 
#contact { 
    background: red; 
    margin: 45px auto 0px auto; 
    width: 600px; 
    height: 500px; 
    display: none; 
} 

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" name="viewport" content="width=device-width, initial-scale=1" /> 
<title>Modeste Web Studio</title> 

<!--Fonts--> 
<link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'> 
<link href='http://fonts.googleapis.com/css?family=Exo+2:400,200' rel='stylesheet' type='text/css'> 

<!--CSS--> 
<link rel="stylesheet" type="text/css" href="css/style.css"/> 
<link rel="stylesheet" type="text/css" href="css/simpletextrotator.css" /> 
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" /> 

<!--Favicon--> 

</head> 

<body> 

    <div id="top"></div> 
    <img class="logo-bg" src="img/logo-bg.png" /> 
    <iframe id="video" type="text/html" src="http://www.youtube.com/embed/ht2TigJp88w?wmode=opaque&autohide=1&autoplay=1&loop=1&playlist=ht2TigJp88w&wmode&start=62&enablejsapi=1" frameborder="0"></iframe> 

    <img class="menuBtn" src="img/banner.png" /> 
    <div class="title"> 
     <p> 
      <span class="rotate">MODESTE,BEAUTIFUL,RELIABLE,MODERN</span> WEB <span class="rotate">STUDIO,DESIGN,DEVELOPMENT,SOLUTIONS</span> 
     </p> 

     <nav> 
      <hr> 
      <ul> 
       <li class="about">ABOUT</li> 
       <li class="works">WORKS</li> 
       <li>BLOG</li> 
       <li class="contact">CONTACT</li> 
      </ul> 
     </nav> 

     <div id="about">ABOUT</div> 
     <div id="works">WORKS</div> 
     <div id="contact">CONTACT</div> 
    </div> 

<!--Javascript--> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> 
<script type="text/javascript" src="js/animatescroll.noeasing.js"></script> 
<script src="http://www.google.com/jsapi"></script> 
<script type="text/javascript" src="js/jquery.simple-text-rotator.js"></script> 
<script type="text/javascript" src="js/application.js"></script> 

</body> 
</html> 

回答

1

有一些問題,你的CSS和HTML,基本上你已經設置爲向左浮動一些元素在.title div和.title div裏面有一個固定的高度,這導致菜單跳出了.title div高度。

以下是更新後的CSS和HTML代碼,可以使菜單按照您所描述的方式工作。

<div class="title"> 
     <p> 
      <span class="rotate">MODESTE,BEAUTIFUL,RELIABLE,MODERN</span> WEB <span class="rotate">STUDIO,DESIGN,DEVELOPMENT,SOLUTIONS</span> 
     </p> 

     <nav> 
      <hr> 
      <ul> 
       <li class="about">ABOUT</li> 
       <li class="works">WORKS</li> 
       <li>BLOG</li> 
       <li class="contact">CONTACT</li> 
      </ul> 
     </nav> 

     <div id="about">ABOUT</div> 
     <div id="works">WORKS</div> 
     <div id="contact">CONTACT</div> 
    </div> 

* { 
    margin: 0; 
    padding: 0; 
} 

a:link, 
a:hover, 
a:active, 
a:visited { 
    text-decoration: none; 
    cursor: pointer; 
} 

body { 
    height: 100%; 
    width: 100%; 
    background: #000; 
    overflow: hidden; 
} 

.logo-bg { 
    z-index: 50; 
    position: relative; 
    top: -230px; 
    width: 802px; 
    height: 803px; 
    margin: 0 auto; 
    display: block; 
} 

#video { 
    position: absolute; 
    top: -40px; 
    left: 50%; 
    margin-left: -360px; 
    width: 720px; 
    height: 500px; 
} 

.title { 
    background: url(../img/paper.jpg); 
    z-index: 51; 
    position: relative; 
    top: -470px; 
    left: 50%; 
    margin-left: -344px; 
    width: 695px; 
    padding: 10px 0; 
    border: 1px solid #fff; 
    -webkit-border-radius: 5px; 
    -moz-border-radius: 5px; 
    border-radius:   5px; 
    -webkit-box-shadow: inset 0px 0px 7px #000; 
    -moz-box-shadow: inset 0px 0px 7px #000; 
    box-shadow:   inset 0px 0px 7px #000; 
} 

.title-menu { 
    height: auto; 
} 

.title-element { 
    height: 627px; 
} 

.title p { 
    color: #f3ffff; 
    display: block; 
    font-family: "Montserrat",sans-serif; 
    font-size: 30px; 
    font-weight: bolder; 
    position: relative; 
    text-align: center; 
    text-shadow:0px 0px 0 rgb(210,210,210),-1px 0px 0 rgb(165,165,165),-2px 0px 0 rgb(120,120,120), -3px 0px 0 rgb(75,75,75),-4px 0px 3px rgba(0,0,0,1),-4px 0px 1px rgba(0,0,0,0.5),0px 0px 3px rgba(0,0,0,.2); 
} 

.menuBtn { 
    z-index: 99; 
    position: absolute; 
    top: 328px; 
    left: 50%; 
    margin-left: 290px; 
    cursor: pointer; 

    -webkit-transition: all 250ms ease; 
    -moz-transition: all 250ms ease; 
    -ms-transition:  all 250ms ease; 
    -o-transition:  all 250ms ease; 
    transition:   all 250ms ease; 

    -webkit-filter: drop-shadow(-2px 1px 1px #777); 
    filter: drop-shadow(-2px 1px 1px #777); 
} 

.menuBtn:active { 
    margin-left: 288px; 
    -webkit-filter: none; 
    filter: none; 
} 

nav { 
    margin-top: 10px; 
    display: none; 
    position: relative; 
    width: 100%; 
} 

hr { 
    opacity: .3; 
    border: 0; 
    height: 1px; 
    background-image: -webkit-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,1), rgba(0,0,0,0)); 
    background-image: -moz-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,1), rgba(0,0,0,0)); 
    background-image:  -ms-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,1), rgba(0,0,0,0)); 
    background-image:  -o-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,1), rgba(0,0,0,0)); 
} 

nav li { 
    color: #eeeeee; 
    cursor: pointer; 
    display: inline-block; 
    font-family: "Exo 2",sans-serif; 
    margin: 10px; 
    text-align: center; 
    text-shadow: -1px 0 1px #000000; 
    transition: all 250ms ease 0s; 
    width: 20%; 

    -webkit-transition: all 250ms ease; 
    -moz-transition: all 250ms ease; 
    -ms-transition:  all 250ms ease; 
    -o-transition:  all 250ms ease; 
    transition:   all 250ms ease; 
} 

nav li:hover { 
    text-shadow: none; 
    color: #444; 
} 

#about, 
#works, 
#contact { 
    background: red; 
    margin: 45px auto 0px auto; 
    width: 600px; 
    height: 500px; 
    display: none; 
} 
+0

這一直有用。這是一個更好的方式來構建HTML和CSS。裏面的div不斷重現,我認爲這是我的jQuery的問題。 – Zenneson 2014-12-13 07:05:17