根据图像地图链接显示不同的内容
Different content shown based on image map link(s)
我有一个图像映射到页面底部的3个链接。点击链接会将相关内容从底部滑入视图。再次点击链接将使内容消失。
假设我点击了链接1,所以内容1是可见的。如果我点击链接2,内容2也会显示。我想要的是,当我点击链接2,内容1消失,内容2显示。等。
是否有可能修改我下面的内容来实现这一点?
张贴代码如下,并有一个例子在这里。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Example</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
jQuery( document ).ready( function() {
jQuery( '#about-text-link' ).click(function() {
jQuery( '#about-text' ).slideToggle( 'slow' );
jQuery( this ).toggleClass( 'active' );
return false;
});
jQuery( '#editions-text-link' ).click(function() {
jQuery( '#editions-text' ).slideToggle( 'slow' );
jQuery( this ).toggleClass( 'active' );
return false;
});
jQuery( '#contact-text-link' ).click(function() {
jQuery( '#contact-text' ).slideToggle( 'slow' );
jQuery( this ).toggleClass( 'active' );
return false;
});
});
</script>
<style type="text/css">
.menu {
background-color: #FFFFFF;
display: none;
overflow: hidden;
border: 1px solid #CCCCCC;
}
#bottom-block {
position: absolute;
width: 435px;
left: 50%;
margin-left: -218px;
}
#bottom-block {
bottom: 0;
}
</style>
</head>
<body>
<div id="page">
<div id="bottom-block">
<img src="menu.png" width="435px;" height="34px;" usemap="#map" />
<map id="_map" name="map">
<area shape="rect" coords="11,6,102,29" href="#" alt="about" title="about" id="about-text-link" />
<area shape="rect" coords="109,6,286,29" href="#" alt="editions" title="editions" id="editions-text-link" />
<area shape="rect" coords="295,6,410,29" href="#" alt="contact" title="contact" id="contact-text-link" />
</map>
<div class="menu" id="about-text">
About text
</div>
<div class="menu" id="editions-text">
Editions text
</div>
<div class="menu" id="contact-text">
Contact text
</div>
</div>
</div>
</body>
</html>
您可以使用document.getElementById(id).style.display = "none";
来隐藏其他元素,在您的代码中添加代码。希望这对你有帮助。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Example</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
jQuery( document ).ready( function() {
jQuery( '#about-text-link' ).click(function() {
jQuery( '#about-text' ).slideToggle( 'slow' );
document.getElementById("editions-text").style.display = "none"; //-->
document.getElementById("contact-text").style.display = "none"; //-->
jQuery( this ).toggleClass( 'active' );
return false;
});
jQuery( '#editions-text-link' ).click(function() {
jQuery( '#editions-text' ).slideToggle( 'slow' );
document.getElementById("about-text").style.display = "none"; // -->
document.getElementById("contact-text").style.display = "none"; // -->
jQuery( this ).toggleClass( 'active' );
return false;
});
jQuery( '#contact-text-link' ).click(function() {
jQuery( '#contact-text' ).slideToggle( 'slow' );
document.getElementById("about-text").style.display = "none"; // -->
document.getElementById("editions-text").style.display = "none"; // -->
jQuery( this ).toggleClass( 'active' );
return false;
});
});
//--> added lines
</script>
<style type="text/css">
.menu {
background-color: #FFFFFF;
display: none;
overflow: hidden;
border: 1px solid #CCCCCC;
}
#bottom-block {
position: absolute;
width: 435px;
left: 50%;
margin-left: -218px;
}
#bottom-block {
bottom: 0;
}
</style>
</head>
<body>
<div id="page">
<div id="bottom-block">
<img src="menu.png" width="435px;" height="34px;" usemap="#map" />
<map id="_map" name="map">
<area shape="rect" coords="11,6,102,29" href="#" alt="about" title="about" id="about-text-link" />
<area shape="rect" coords="109,6,286,29" href="#" alt="editions" title="editions" id="editions-text-link" />
<area shape="rect" coords="295,6,410,29" href="#" alt="contact" title="contact" id="contact-text-link" />
</map>
<div class="menu" id="about-text">
About text
</div>
<div class="menu" id="editions-text">
Editions text
</div>
<div class="menu" id="contact-text">
Contact text
</div>
</div>
</div>
</body>
</html>
相关文章:
- 使用JSP从服务器检索和显示图像
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- 使用FormData上传AJAX图像;t在服务器端显示图像
- 选择文件后显示图像
- Chrome(webkit?)无法在幻灯片中正确显示图像
- 如何使用javascript显示图像
- 使用JS按顺序显示图像,而不是随机显示
- 使用服务器上的HTML/js在网页上显示图像
- 我想在选择输入文件上显示图像
- Javascript:单击单选按钮时显示图像
- 如何将JSON结果设置为'src'共'img'以在ASP.NET MVC4中显示图像
- 无法在cakepp布局中显示图像
- 页面加载后通过javascript显示图像
- 将图像文件存储在猫鼬模式中的二进制数据中,并以html形式显示图像
- 使用AngularJs数据绑定的三元运算符显示图像
- 加载时画布上未显示图像
- 运行POST时显示图像
- NodeJS上没有显示图像
- 从Javascript在表中显示图像
- 如何在MVC5中运行时在HTML5 Canvas中显示图像