我设计了一个简单的网页,这里是html代码
<div class="wrap-01">
<div class="wrap-02">
<div class="about">
<p> some content </p>
</div> <!-- end about page -->
<div class="contact">
<p> some content </p>
</div> <!-- end contact page -->
<div class="service">
<p> some content </p>
</div> <!-- end service page -->
<div class="quotes">
<blockquote>
<p>“ some quote ” - author - </p>
</blockquote>
<blockquote>
<p>“ some quote ” - author - </p>
</blockquote>
<blockquote>
<p>“ some quote ” - author - </p>
</blockquote>
<blockquote>
<p>“ some quote ” - author - </p>
</blockquote>
</div> <!-- end quotes page -->
</div> <!-- end wrap 02 -->
<div class="wrap-03">
<a href="#" class="link-01"> About <br /> <span> some text </span> </a>
<a href="#" class="link-02"> Contact <br /> <span> some text </span> </a>
<a href="#" class="link-03"> Service <br /> <span> some text </span> </a>
</div> <!-- end wrap 03 -->
</div> <!-- end wrap 01 -->
我为这个html编码写了css,这是
@charset "utf-8";
/* CSS Document */
body{font-family: Arial;}
.wrap-01{
width: 740px;
padding: 20px;
margin: auto;
}
.about, .contact, .service, .quotes{
height: 350px;
width: 700px;
background: #fff;
}
.wrap-02{
position: relative;
}
.wrap-03{
padding-right: 30px;
padding-left: 30px;
}
.about, .contact, .service{
position: absolute;
display: none;
}
.about p, .contact p, .service p{
font-size: 15px;
padding: 10px 25px 10px 25px;
text-align: justify;
}
.my-link{
float: left;
background: orange;
margin-top: 50px;
margin-bottom: 0;
text-decoration: none;
color: #fff;
font-size: 20px;
padding: 20px 20px 0 20px;
}
.link-01{
margin-right: 10px;
}
.link-02{
margin-right: 10px;
margin-left: 10px;
}
.link-03{
margin-left: 10px;
}
这是我的jQuery代码
<script type="text/javascript">
$(document).ready(function(){
$(".link-01").click(function(){
$(".about").fadeIn("slow");
$(".contact").fadeOut("slow");
$(".service").fadeOut("slow");
$(".quotes").fadeOut("slow");
});
});
</script>
所以现在我想保持,联系,服务,引用div这个顺序当页面加载引号div应该首先显示而其他(关于,联系人,服务)应该隐藏,当我点击链接-01关于链接应该显示和其他人(联系人,服务,报价)应该使用jQuery fadeIn和fadeOut效果隐藏所以我想对其他人这样做(link-02和link-03)。
现在我想知道如何正确地做这件事 是这个jQuery代码错误或这是不正确的? 当我点击链接-01所有wrap-03得到隐藏为什么会这样?
答案 0 :(得分:1)
<script type="text/javascript">
$(document).ready(function(){
$(".link-01").click(function(){
$(".wrap-02 div").hide('slow',function(){
$(".about").fadeIn("slow");
});
});
});
</script>
或者如果您对标记进行了一些更改,可以概括一下,
<script type="text/javascript">
$(".wrap-03 a").click(function(){
var className = $(this).attr("id");
$(".wrap-02 div").hide('slow',function(){
$("."+className).fadeIn("slow");
});
});
</script>
<div class="wrap-01">
<div class="wrap-02">
<div class="about">
<p> some content </p>
</div> <!-- end about page -->
<div class="contact">
<p> some content </p>
</div> <!-- end contact page -->
<div class="service">
<p> some content </p>
</div> <!-- end service page -->
<div class="quotes">
</div> <!-- end quotes page -->
</div> <!-- end wrap 02 -->
<div class="wrap-03">
<a href="#" id="about" class="link-01"> About <br /> <span> some text </span> </a>
<a href="#" id="contact" class="link-02"> Contact <br /> <span> some text </span> </a>
<a href="#" id="service" class="link-03"> Service <br /> <span> some text </span> </a>
</div> <!-- end wrap 03 -->
</div>
答案 1 :(得分:1)
这里有一个基于JS和标记的jsFiddle和一个工作示例。你需要调整你的CSS,我不擅长。