2016-01-09 76 views
0

我想讓我的標題文本有一個下劃線動畫,當用戶向下滾動並且標題框2變爲可見時。我應該怎麼做?使用J-Query?如何在網頁上顯示文字時將文字加下劃線?

一個例子是我向下滾動到我的第一部分,一旦標題框2我希望它下劃線標題框2的文本。

我想要做的這個標題是header-box-2。

<!DOCTYPE html> 
<html> 
<head> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link href="swdd.css" rel="stylesheet"> 
    <link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 

</head> 
<body> 
    <a href="#" id="open">menu</a> 
    <nav class="nav-fixed-clear"> 
     <ul> 
      <li><a href="#">home</a></li> 
      <li><a href="#about">about</a></li> 
      <li><a href="#services">services</a></li> 
      <li><a href="#portfolio">portfolio</a></li> 
      <li><a href="#contactme">contact us</a></li> 
     </ul> 
    </nav> 

    <script> 
     $("#open").click(function() { 
      $(".nav-fixed-clear").slideToggle(300, function() { 
       $(this).toggleClass("nav-expanded").css("display", ""); 
      }); 
     }); 
    </script> 

    <div class="home-box"> 
     <div class="welcome-box"> 
      <div class="header-box-1"> 
       <h1>hello there.</h1> 
      </div> 
      <div class="para-box-1"> 
       <p>my name is syd.</p> 
      </div> 
     </div> 
    </div> 

    <a href="#" name="about"></a> 
    <div class="section-box-1"> 
     <div class="content-box-1"> 
      <div class="header-box-2"> 
       <h2>Who am I?</h2> 
      </div> 
      <div class="para-box-1"> 
       <p>My name is Syd. I am web designer and developer. </p> 
      </div> 
     </div> 
    </div> 

    <a href="#" name="services"></a> 
    <div class="section-box-2"> 
     <div class="content-box-1"> 
      <div class="header-box-2"> 
       <h2>My services: </h2> 
      </div> 
      <div class="para-box-1"> 
       <p>I specialize single-page web design. What makes me unique from many web designers today is that I code my websites from scratch. Because of this I can create a truly original design for you. </p> 
      </div> 
     </div> 
    </div> 

</body> 
</html> 

body {margin: 0; padding: 0;} 
 

 
/*********************/ 
 
/* \t \t \t \t  \t */ 
 
/* \t nav-fixed-clear */ 
 
/* \t \t \t \t  */ 
 
/*********************/ 
 

 
/* This navigation bar is best for websites with light backgrounds. */ 
 

 
.nav-fixed-clear { 
 
\t position: fixed; 
 
\t width: 100%; 
 
\t border-bottom: 1px solid transparent; 
 
\t transition: border ease-in-out 1s; 
 
\t z-index: 3; 
 
} 
 

 
.nav-fixed-clear:hover { 
 
\t border-color: #000000; 
 
} 
 

 
.nav-fixed-clear ul { 
 
\t list-style: none; 
 
\t margin: 0 auto; 
 
\t width: 70%; 
 
} 
 

 
.nav-fixed-clear li { 
 
\t display: block; 
 
} 
 

 
.nav-fixed-clear a { 
 
\t color: #000000; 
 
\t float: left; 
 
\t margin: 1% 6%; 
 
\t text-decoration: none; 
 
\t font-family: 'Roboto', sans-serif; 
 
    border-bottom: 1px solid transparent; 
 
\t transition: border ease-in-out .5s; 
 
\t font-size: 1em; 
 
} 
 

 
.nav-fixed-clear a:hover { 
 
\t border-color: red; 
 
\t 
 
} 
 

 
#open { 
 
\t display: none; 
 
\t font-family: 'Roboto', sans-serif; 
 
\t color: #000000; 
 
\t text-decoration: none; 
 
\t margin: 0; 
 
\t padding: 2%; 
 
\t 
 
\t border-bottom: 3px solid black; 
 
} 
 

 

 

 
@media only screen and (max-width: 990px) { 
 
\t .nav-fixed-clear { 
 
\t \t border-bottom: none; 
 
\t \t transition: none; 
 
\t \t display: none; 
 
\t \t position: static; 
 
\t } 
 
\t .nav-fixed-clear ul { 
 
\t \t padding: 0; 
 
\t \t margin: 0; 
 
\t \t width: 100% 
 
\t } 
 
\t 
 
\t .nav-fixed-clear li { 
 
\t \t padding: 2%; 
 
\t \t border-bottom: 1px solid gray; 
 
\t \t width: 100%; 
 
\t } 
 
\t 
 
\t .nav-fixed-clear a { 
 
\t \t float: none; 
 
\t \t margin: 0; 
 
\t 
 
\t } 
 
\t 
 
\t #open { 
 
\t \t display: block; 
 
\t \t 
 
\t } 
 
\t 
 
\t 
 
\t .nav-expanded { 
 
\t \t display: block; 
 
\t \t 
 
\t } 
 
} 
 

 
.home-box { 
 
\t width: 100%; 
 
\t height: 100vh; 
 
\t position: absolute; 
 
} 
 

 
.welcome-box { 
 
\t width: 65%; 
 
\t margin: 0 auto; 
 
\t margin-top: 20%; 
 
\t font-family: 'Roboto', sans-serif; 
 
} 
 

 
.header-box-1 { 
 
\t font-size: 2em; 
 
\t color: #333333; 
 
} 
 

 
.para-box-1 { 
 
\t font-size: 1.2em; 
 
\t color: #4d4d4d; 
 
\t text-transform: lowercase; 
 
} 
 

 
.section-box-1 { 
 
\t top: 100%; 
 
\t height: 100vh; 
 
\t width: 100%; 
 
\t position: absolute; 
 
} 
 

 
.content-box-1 { 
 
\t font-family: 'Roboto', sans-serif; 
 
\t width: 65%; 
 
\t margin: 0 auto; 
 
\t margin-top: 5%; 
 
} 
 

 
.header-box-2 { 
 
\t font-size: 1.5em; 
 
\t color: #333333; 
 
\t text-transform: lowercase; 
 
} 
 

 
.section-box-2 { 
 
\t top: 200%; 
 
\t height: 100vh; 
 
\t width: 100%; 
 
\t position: absolute; 
 
}

回答

1

點擊[https://jsfiddle.net/up4nu/]這個樣本編碼這將是對你有所幫助

+0

這是使用jQuery? – sydluce

0

嘗試使用自舉詞綴概念

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <title>Bootstrap Example</title> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
    <style> 
    body { 
     position: relative; 
    } 
    .affix { 
     top: 20px; 
    } 
    div.col-sm-9 div { 
     height: 250px; 
     font-size: 28px; 
    } 
    #section1 {color: #fff; background-color: #1E88E5;} 
    #section2 {color: #fff; background-color: #673ab7;} 
    #section3 {color: #fff; background-color: #ff9800;} 
    #section41 {color: #fff; background-color: #00bcd4;} 
    #section42 {color: #fff; background-color: #009688;} 

    @media screen and (max-width: 810px) { 
    #section1, #section2, #section3, #section41, #section42 { 
     margin-left: 150px; 
    } 
    } 
    </style> 
</head> 
<body data-spy="scroll" data-target="#myScrollspy" data-offset="15"> 

<div class="container-fluid" style="background-color:#2196F3;color:#fff;height:200px;"> 
    <h1>Scrollspy & Affix Example</h1> 
    <h3>Fixed vertical sidenav on scroll</h3> 
    <p>Scroll this page to see how the navbar behaves with data-spy="affix" and data-spy="scrollspy".</p> 
    <p>The left menu sticks the page after you have scrolled a specified amount of pixels, and the links in the menu are automatically updated based on scroll position.</p> 
</div> 
<br> 

<div class="container"> 
    <div class="row"> 
    <nav class="col-sm-3" id="myScrollspy"> 
     <ul class="nav nav-pills nav-stacked" data-spy="affix" data-offset-top="205"> 
     <li><a href="#section1">Section 1</a></li> 
     <li><a href="#section2">Section 2</a></li> 
     <li><a href="#section3">Section 3</a></li> 
     <li class="dropdown"> 
      <a class="dropdown-toggle" data-toggle="dropdown" href="#">Section 4 <span class="caret"></span></a> 
      <ul class="dropdown-menu"> 
      <li><a href="#section41">Section 4-1</a></li> 
      <li><a href="#section42">Section 4-2</a></li>      
      </ul> 
     </li> 
     </ul> 
    </nav> 
    <div class="col-sm-9"> 
     <div id="section1">  
     <h1>Section 1</h1> 
     <p>Try to scroll this section and look at the navigation list while scrolling!</p> 
     </div> 
     <div id="section2"> 
     <h1>Section 2</h1> 
     <p>Try to scroll this section and look at the navigation list while scrolling!</p> 
     </div>   
     <div id="section3">   
     <h1>Section 3</h1> 
     <p>Try to scroll this section and look at the navigation list while scrolling!</p> 
     </div> 
     <div id="section41">   
     <h1>Section 4-1</h1> 
     <p>Try to scroll this section and look at the navigation list while scrolling!</p> 
     </div>  
     <div id="section42">   
     <h1>Section 4-2</h1> 
     <p>Try to scroll this section and look at the navigation list while scrolling!</p> 
     </div> 
    </div> 
    </div> 
</div> 

</body> 
</html>