我是JQuery的新手,我一直在努力练习。我正在使用悬停功能来更改文本。问题是文本正在改变,但文本没有继承我想要它的类属性。
以下是我的问题的解答:http://jsfiddle.net/byMUy/
#basecamp应该接收“hidden”类属性(或者每个元素选择器的所有属性)。当我悬停时(在左下角的第一个方框)。文本更改但它不会继承我想要的类(隐藏)。当我在悬停后检查源时,我看到该类更改为隐藏。我试图弄清楚如何确保我的“隐藏的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>®</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>®</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>™</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;
}
JQuery的:
$(document).ready(function () {
/*console.log("hello")*/
$('.basecamp a').hover(function () {
$(".header").addClass('hidden');
$("#basecamp").removeClass("hidden");
},
function () {
});
});
答案 0 :(得分:1)
我不确定你想要实现什么,但我认为你把几个ID与类混淆了,这就是为什么你不能让这个工作。
我对您的代码进行了一些更改,我认为它现在正在运行(如果这是您想要实现的) 你需要编辑一下你的css,以便当你将鼠标悬停在底部框上时“Basecamp”更合适。
选中 EXAMPLE
Hope this helps
答案 1 :(得分:0)
试试这个:
$('.basecamp a').hover(function() {
$(".header").hide();
$("#basecamp").show();
},
答案 2 :(得分:0)
或者您可以在css中添加另一个类,并在删除隐藏类后将该类添加到.basecamp