当鼠标悬停在HTML/JS/JQUERY列表上时,图像弹出
Image pop when hover over a list in HTML/JS/JQUERY
我希望这些图像是可见的,当我把它们悬停在文本。但根据这个,它工作,但它只选择第一个,因为每个图像都有相同的id。请任何人知道如何解决这个问题。这是我的第一篇文章。如果我在发帖时做错了什么,请原谅。提前谢谢。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Selectable - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
<script type = "text/javascript" src = "js/jquery.js"></script>
<script type = "text/javascript" src = "js/jquery_ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<style>
#feedback { font-size: 1.4em; }
#selectable .ui-selecting { background: #FECA40; }
#selectable .ui-selected { background: #F39814; color: white; }
#selectable { list-style-type: none; margin: 0; padding: 0; width: 20%; }
#selectable li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
img
{
position:absolute;
left:250px;
display:none;
}
</style>
<script>
$(function() {
$( "#selectable" ).selectable();
});
</script>
</head>
<body>
<table id="myTable">
<td>
<tr>
<ol id="selectable" onmouseover="show(next,true)" onmouseout="show(next,false)">
<li>Item 1 <img src="next.jpg" id="next"></li>
<li>Item 2 <img src="next.jpg" id="next"></li>
<li>Item 3 <img src="next.jpg" id="next"></li>
<li>Item 4 <img src="next.jpg" id="next"></li>
<li>Item 5 <img src="next.jpg" id="next"></li>
</ol>
</tr>
</td>
</table>
<script type = "text/javascript">
$(document).ready(function() {
$('#selectable').fadeIn('very slow');
});
</script>
<script language="javascript">
//function to display the immage
function show(id,disp) {
if (disp == true) {
id.style.display = "block";
}
if (disp == false) {
id.style.display = "none";
}
}
</script>
</body>
</html>
在使用ID进行处理时使用以下方法,使ID不同
<li>Item 1 <img src="next.jpg" id="next1" ></li>
<li>Item 2 <img src="next.jpg" id="next2" ></li>
<li>Item 3 <img src="next.jpg" id="next3" ></li>
<li>Item 4 <img src="next.jpg" id="next4" ></li>
<li>Item 5 <img src="next.jpg" id="next5" ></li>
元素的id不能相同。您可以使用相同的类,并在show函数中传递类名。
更新:在单个列表上设置mouseover和mouseout事件,而不是单独获取特定元素。
<ol id="selectable">
<li>Item 1 <img src="next.jpg" class="next" onmouseover="show(this,true)" onmouseout="show(next,false)"></li>
<li>Item 2 <img src="next.jpg" class="next" onmouseover="show(this,true)" onmouseout="show(next,false)"></li>
<li>Item 3 <img src="next.jpg" class="next" onmouseover="show(this,true)" onmouseout="show(next,false)"></li>
<li>Item 4 <img src="next.jpg" class="next" onmouseover="show(this,true)" onmouseout="show(next,false)"></li>
<li>Item 5 <img src="next.jpg" class="next" onmouseover="show(this,true)" onmouseout="show(next,false)"></li>
</ol>
你的show函数:
function show(clickedObj,disp) {
if (disp == true) {
clickedObj.style.display = "block";
}
if (disp == false) {
clickedObj.style.display = "none";
}
}
相关文章:
- 如何从 URL 数组向文档添加图像列表
- 如何创建背景图像列表'URL,并使用jQuery在单击函数时应用它们
- 网页上已有tinymce加载图像列表
- 如何使用javascript获取文件夹中的图像列表
- 使用JavaScript或JQuery从cloudinary获取图像列表
- 调用照片在图像列表上滑动的简单方法
- JQuery 和 Bootstrap:如何将图像列表中的图像添加到轮播
- 包含文本和 URL 的图像列表视图
- 按图像计数变量显示图像列表
- 在段落列表后插入图像列表
- 在哪里可以找到dojo工具箱dijit小部件的图标图像列表
- 在 Node.js 中使用 OpenCV 加载图像列表
- 如何让jQuery等待图像列表加载后再处理它们
- 如何使用jquery从图像列表中获取单击图像的属性
- 带有Angular和Angular材质的图像列表
- 如何在web编程中显示适合屏幕的图像列表
- 如何从客户端 JavaScript 从 cloudinary 获取我的图像列表
- 在图像列表中导航的最简单方法是什么?
- 如何在图像列表中移动元素?与JQuery
- 按顺序加载图像列表