jQuery 网易相册鼠标移动显示隐藏效果实现代码

2020-05-24 21:25:44易采站长站整理

其实主要是jquery 层选择器的应用,jquery 高手可以跳过。。。


网易相册效果图如下:当鼠标移动经过照片就显示“设为封面|删除”,移开后就隐藏,此效果在web开发中经常会用到。故总结一下



直接上代码:

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>Insert title here</title>
<style type=”text/css”>
.al_info{display: none;}
#imgdiv {float: left;width: 170px;height: 130px; display: block; padding:15px 10px;}
#imgdiv img{width:160px;height:140px;}
</style>
<script type=”text/javascript” src=”../js/jquery.min.js”></script>
<script type=”text/javascript”>
jQuery(document).ready(function(){
jQuery(“#imgvv div”).hover(function() {
jQuery(this).find(“#oper”).show().find(“a”).attr(“href”,”javascript:void(0)”);
}, function() {
jQuery(this).find(“#oper”).hide();
});
});
</script>
</head>
<body>
<div id=”imgvv”>
<div id=”imgdiv”>
<span class=”albumsDiv” onclick=”showphoto(61)”><img
title=”myhome photo” alt=”myHOME”
src=”/FileManager/upload/photo/l9pztyhx5tY=/nJnRixC/lG8=/e400bd4c851240459db967b721c5101e_a.JPG”>
</span><br>
<span title=”myHOME” class=”name”>myHOME</span> <span class=”al_info”>共2张照片
</span> <br>
<span class=”al_info” id=”oper”><a href=”#”>编辑属性</a>|<a
href=”#”>删除</a>
</span>
</div>
<div id=”imgdiv”>
<span class=”albumsDiv” onclick=”showphoto(61)”><img
title=”myhome photo” alt=”myHOME”
src=”/FileManager/upload/photo/l9pztyhx5tY=/nJnRixC/lG8=/e400bd4c851240459db967b721c5101e_a.JPG”>
</span><br>
<span title=”myHOME” class=”name”>myHOME</span> <span class=”al_info”>共2张照片
</span> <br>
<span class=”al_info” id=”oper”><a href=”#”>编辑属性</a>|<a
href=”#”>删除</a>
</span>
</div>
<div id=”imgdiv”>
<span class=”albumsDiv” onclick=”showphoto(61)”><img