0

我是 JQuery 的新手,在我一直在做的练习中遇到了一些麻烦。我正在使用悬停功能来更改文本。问题是文本正在改变,但文本没有继承我想要的类属性。

这是我的问题的 jsfiddle:http: //jsfiddle.net/byMUy/

#basecamp 应该接收“隐藏”类属性(或每个元素选择器的所有属性)。当我悬停时(在左下角的第一个框上)。文本更改但它不继承我希望它(隐藏)的类。当我悬停后检查源代码时,我看到该类更改为隐藏。我试图弄清楚如何确保我的“隐藏的 h1、隐藏的 h5 等”被继承,我认为这可能是问题所在。

我的主要问题是:在我悬停(在左下角的框上)之后,为什么我的新文本不继承我的 CSS 中的隐藏属性?它应该看起来与悬停之前的外观非常相似,只是标题文本发生了变化。

这是我的源代码:

谢谢!

**我意识到我在 Jquery 中的“功能”已经完成,因为我的悬停尚未填写。我主要专注于使第一部分正确。

HTML:

<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="main.css">
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script src="application.js"></script>
        <title>37signals</title>
    </head>

    <body>
        <nav>
            <ul>
                <li><a href="#">Company blog</a>
                </li>
                <li><a href="#">Our story</a>
                </li>
                <li><a href="#">Follow us on Twitter</a>
                </li>
                <li><a href="#">System status</a>
                </li>
                <li><a href="#">Sign in</a>
                </li>
            </ul>
        </nav>
        <div class="header">
            <img src="images/logo-37s-large.png" alt="37signals" />
             <h1>Making collaboration productive and enjoyable for people every day.</h1>

             <h5>Frustration-free web-based apps for collaboration, sharing information, and making decisions.<h5> 
    </div>



     <div class = "hidden" id ="basecamp">
      <img src= "images/logo-37s-large.png" alt="37signals" />
        <h1><a href="#">Basecamp</a> is the project management tool you wish you had on your last project</h1>
        <h5>Are you still managing projects with email? Are you still using Excel for your to-do lists? It's time to upgrade to Basecamp.  Manage projects and collaborate with your team and clients the modern way.</h5> 
            <div class="hidden arrow">
                <img src="images/arrow-left.png">
            </div>
        </div>
        <section class="basecamp"> <a href="#" class="bc">
          <img src = "images/logo-bc.png"/>
          <h3>Basecamp<sup>&reg;</sup><h3>
          <h4>Manage Projects</h4>
          <p>Used by millions for project management</p>
        </a>
 <a href="#" class="hr">
            <img src="images/logo-hr.png" />
            <h3><span>Highrise</span><sup>&reg;</sup></h3>
            <h4>Manage Contacts</h4>
            <p>Know the people you do business with.</p>
          </a>
 <a href="#" class="cf">
            <img src="images/logo-cf.png" />
            <h3><span>Campfire</span><sup>&trade;</sup></h3>
            <h4>Work in Real-Time</h4>
            <p>Group chat rooms for your business.</p>
            </a>

        </section>
        <hr />
    </body>

CSS:

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
  display: block;
}
body {
  line-height: 1;
}
ol, ul {
  list-style: none;
}
blockquote, q {
  quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
  content: '';
  content: none;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
}
/* START */

a {
  text-decoration: none;
  color: #369;
}

section {
  margin: 30px auto;
  width: 825px;
  display: block; 
}

sup {
  color:#999;
  font-weight: normal;
  font-size: 11px;
}

hr {
  background: url('images/img-hr.png') no-repeat scroll 50% 50%;
  clear: both;
  border: none;
  color: transparent;
  height: 12px;
}

@font-face {
  font-family: CrimsonSemiBold;
  src: url('Crimson-Semibold.otf'); 
}

@font-face {
  font-family: CrimsonRoman;
  src: url('Crimson-Roman.otf');  
}


/* NAV BAR */

nav {
  min-width: 100%;
  height: 48px;
  font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, sans-serif;  
}


nav ul {
  float: right;
  font-family: Arial, Verdana;
  margin: 12px 18px;
  padding: 10px 30px;
}

nav li {
  margin: 15px 5px 15px 6px;
  padding: 5px 4px;
  font-size: 12px;
  display: inline;
  color: #369;
}

.header {
  clear: both;
  width: 829px; 
  height: 163px;
  margin: 0 auto; 
  padding: 6px 0;
  text-align: center;
  font-family: "CrimsonSemiBold", "Times New Roman", Georgia, serif;
}

.header h1 {
  font-weight: 500;
  font-size: 58px;
  line-height: 1em; 
  margin: 10px 0 20px 0;
  letter-spacing: -2px;
  color: #232323;
  clear: both;
}

.header h5 {
  font-weight: 500;
  font-size: 20px;  
  line-height: 1.5em;
  margin: 10px 0;
  color: #222;
}
/* jquery hidden classes */

.hidden {
  display:none;
  clear: both;
  text-align: center;
  font-family: "CrimsonSemiBold", "Times New Roman", Georgia, serif;
  width: 829px;
  height: 163px;
  margin: 0 auto;
  padding: 6px 0;
}

.hide {
  display: none;
}

.hidden h1 {

  font-weight: 500;
  font-size: 40px;
  line-height: 1em; 
  margin: 10px 0 20px 0;
  letter-spacing: -2px;
  color: #232323;
  clear: both;
}
.hidden h5 {

  font-weight: 500;
  font-size: 16px;  
  line-height: 1.5em;
  margin: 10px 0;
  color: #222;
}
.hidden a {
  text-decoration: underline;
}

.hidden arrow {

  position: absolute;
  top: 300px;
  left: 815px;
  clear: both;
  z-index: 1;
} 
/* Boxes */ 

.basecamp {
  clear:both;
  text-align: center;
  height: 288px;
  padding-bottom: 30px;
  font-family: 'Lucida Grande', 'Lucida Sans Unicode' Verdana, sans-serif;
  z-index: 0;
}

.basecamp h3 {
  text-decoration: underline;
  font-size: 21px;
  font-weight: bold; 
  line-height: 1.5em;
  margin: 0 0 10px 0;
}


.basecamp h4 {
  color: #CC0000;
  margin: 5px 0 10px;
  font-size: 14px;
}

.basecamp p {
  margin: 5px 0;
  -webkit-margin-before: 1em;
  -webkit-margin-after: 1em;
  -webkit-margin-start: 0px;
  -webkit-margin-end: 0px;
  font-size: 14px;
  color: #222;
  line-height: 1.4em;
}

.basecamp a {
  position: relative;
  top: 40px;
  left: 75px; 
  width: 160px; 
  margin: 15px 20px 5px; 
  float: left; 
  border: 1px solid #E8E8E8;
  border-radius: 5px;
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  -webkit-box-shadow: 0 0 5px #EFEFEF;
  -moz-box-shadow: 0 0 5px #efefef;
  box-shadow:0 0 5px #EFEFEF;
  padding: 20px 10px 10px;
  text-decoration: none;
  font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, sans-serif;
  background: -webkit-gradient(linear, left top, left bottom, from(white), to(#EFEFEF));
  background: -moz-linear-gradient(top, white, #EFEFEF);
  clear: none;
}

查询:

$(document).ready(function () {
    /*console.log("hello")*/
    $('.basecamp a').hover(function () {

        $(".header").addClass('hidden');
        $("#basecamp").removeClass("hidden");
    },

    function () {

    });
});
4

3 回答 3

1

我不确定您到底想要实现什么,但我认为您将几个 ID 与类混淆了,这就是您无法完成这项工作的原因。

我对您的代码进行了一些更改,我认为它现在可以工作(如果这是您想要实现的)您需要编辑一些 CSS,以便当您将鼠标悬停在底盒。

检查这个示例

Hope this helps
于 2013-08-28T04:36:50.223 回答
0

尝试这个:

  $('.basecamp a').hover(function() {
         $(".header").hide();
         $("#basecamp").show();  
  },
于 2013-08-28T04:26:15.443 回答
0

实际上,您正在为隐藏的元素赋予样式。那么你怎么能看到它们......你从 .basecamp 中删除了隐藏的类,因此不会有任何 .hidden h1 和 h5 样式。知道了?

或者您可以在 css 中提供另一个类,并在删除隐藏类后将该类添加到 .basecamp

于 2013-08-28T04:45:25.387 回答