jq鼠标经过隐藏当前显示另一个

本文介绍了一种使用Ajax从服务器获取合作伙伴数据的方法,并展示了如何利用这些数据动态生成网页上的列表项。通过具体的JavaScript代码示例,文章详细解释了数据加载过程、列表项的构建以及鼠标悬停效果的实现。
$.ajax({
url: "http://47.92.54.124:8080/platform/partner/partnerApi",
type: "post",
dataType: "jsonp",
contentType: "application/x-www-form-urlencoded;charset=UTF-8",
async: false,
cache: false,
success: function(dataa) {
var partnershtml = "";
var partenrshurl = "";
var partnersdata = dataa.data;
for(var j = 0; j < partnersdata.length; j++) {
var objsa = partnersdata[j];
partenrshurl = objsa.URL;
if(objsa.URL == null) {
partenrshurl = "#";
}
partnershtml += '<li style="cursor: pointer;"> <a><span class="v1"><img src="' +
objsa.logo + '" width="226" height="154" /><span class="div"><p class="txt1">' +
objsa.name + '</p></span></span></a></li>';
}
$('.sis-li').html(partnershtml);


// $("span.div").hide();


$(".sis-li li").hover(function() {
$("span.div", this).fadeIn(300);
$(this).siblings().find("span.div").hide();
}, function() {
$("span.div", this).fadeOut(100);
});


},
error: function(dataa) {
console.log('links:' + data);
}

});


css:

#partner{width:100%; height: auto;padding-bottom: 100px; overflow: hidden;/*padding-top: 90px;*/background: white;}
#partner #center{width:1201px; height: 100%; margin: 0px auto;}
#partner  p.big_title{font-size: 28px; color: #333333;text-align: center;padding-top: 4px;padding-bottom: 10px;/*margin-left: -100px;*/ /*background:  url("../images/title_center.png") no-repeat center 48px;*/background-size: 9% 2%;margin-top: 40px;}
#partner #center li{width: 200px;height: 149px;/*border: 1px solid;*/border-bottom: 1px solid #EDEDED;
border-left: 1px solid #EDEDED;}
#partner #center ul.sis-li span.hid_div{width: 186px;
                                        position: absolute;
                                        z-index: 10;
                                        background: #F00;
                                        FILTER: alpha(opacity=60);
                                        opacity: 0.7;
                                        -moz-opacity: 0.7;
                                        left: 10px;
                                        bottom: 15px;
                                        height: 110px;
                                        float: left;
                                        text-align: left;
                                        padding: 15px 12px 0 12px;}
ul.sis-li{ margin:0 auto; width:100%; overflow:hidden;margin-top: 25px;border-top: 1px solid #EDEDED;
border-right: 1px solid #EDEDED;}
ul.sis-li li{ float:left; padding-top:11px; width:228px; overflow:hidden; padding-right:22px}
ul.sis-li li .v1{float:left;width:200px; position:relative; height:149px; color:#7F7F7F;top: -10px;}
/*ul.sis-li li .v2{ padding-top:6px; width:100%; float:left; overflow:hidden}*/
ul.sis-li li .v1 img{ width:200px; position:absolute; left:0; top:0; z-index:5; height:148px}
ul.sis-li li .v1 .div{display: none; width:200px; position:absolute; z-index:10; background:#FF931A;/*border: 1px solid #e3b037; */FILTER:alpha(opacity=90); opacity:0.9; -moz-opacity:0.9; left:0px;bottom:0px; height:160px; float:left; text-align:center; padding:70px 12px 0 12px}
ul.sis-li li .v1 .div h3{ line-height:20px; padding-bottom:10px; display:block;color:#FFF; overflow:hidden}
ul.sis-li li .v1 .div .txt{ line-height:18px; height:80px; display:block;color:#FFF; overflow:hidden;font-size: 20px;}
ul.sis-li li .v1 .div .txt1{color:#fff; font-size: 20px;margin-bottom: 7px;}



样式参考“01cto。com”

<think>我们将使用jQuery实现一个功能:当鼠标悬停在一个上时,显示遮罩层;当鼠标离开时,隐藏遮罩层。 假设我们有一个容器(例如一个div),里面包含内容和一个遮罩层(通常是一个覆盖整个容层的半透明层)。 结构示例: <div class="container"> ... 内容 ... <div class="mask"></div> <!-- 遮罩层 --> </div> 样式上,遮罩层默认隐藏(比如display: none; 或者 opacity: 0; 结合transition可以实现渐变效果),然后当鼠标悬停在容器上时,遮罩层显示。 使用jQuery,我们可以监听容器的mouseenter和mouseleave事件,然后对遮罩层进行显示隐藏操作。 下面是一个示例代码,包括HTML结构、CSS样式和jQuery代码。</think>### 使用 jQuery 实现鼠标悬停显示遮罩层 以下是完整的实现方案,包含 HTML 结构、CSS 样式和 jQuery 代码: ```html <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>jQuery 遮罩层效果</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style> .container { position: relative; width: 300px; height: 200px; overflow: hidden; border: 1px solid #ccc; } .content { width: 100%; height: 100%; background-color: #f0f0f0; display: flex; align-items: center; justify-content: center; } .mask { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.7); color: white; display: flex; align-items: center; justify-content: center; opacity: 0; /* 初始完全透明 */ transition: opacity 0.3s ease; /* 添加渐变效果 */ } </style> </head> <body> <div class="container"> <div class="content">悬停区域</div> <div class="mask">遮罩层内容</div> </div> <script> $(document).ready(function() { // 鼠标进入时显示遮罩层 $('.container').hover( function() { $(this).find('.mask').stop().fadeTo(200, 1); // 200ms内渐变到不透明 }, function() { $(this).find('.mask').stop().fadeTo(200, 0); // 200ms内渐变到透明 } ); }); </script> </body> </html> ``` ### 代码解释: 1. **HTML 结构**: - `.container`:作为定位基准的容器 - `.content`:显示主要内容区域 - `.mask`:半透明的遮罩层(初始不可见) 2. **CSS 关键点**: - `position: relative` 容器设为相对定位 - `position: absolute` 遮罩层绝对定位覆盖整个容器 - `opacity: 0` 初始完全透明 - `transition` 添加透明度渐变效果 - `rgba(0,0,0,0.7)` 黑色半透明背景 3. **jQuery 逻辑**: - `hover()` 方法:监听鼠标进入/离开事件 - `fadeTo()` 方法:平滑改变透明度(避免显示/隐藏的突兀变化) - `stop()` 方法:停止当前动画,防止多次触发导致的动画队列堆积 - 参数说明: - 200:动画时长(毫秒) - 1:鼠标进入时透明度变为 1(完全不透明) - 0:鼠标离开时透明度变为 0(完全透明) ### 进阶优化建议: 1. 添加遮罩层内容动画(如文字从下方滑入) 2. 支持移动设备的触摸事件 3. 实现点击遮罩层触发操作 4. 添加多重遮罩层或嵌套效果
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值