jquery鼠标hover事件文字内容滑动遮罩效果

本文介绍了如何使用jQuery实现鼠标hover时,文字内容产生滑动遮罩的特效。步骤包括引入jQuery库,编写HTML结构,设计CSS样式,以及编写jQuery代码来控制文字滑动效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果图

这里写图片描述=>这里写图片描述

第一步,首先引入jquery.min.js文件

第二步,写html代码

<div class="item-wrap">
    <div class="item">
        <ul>
            <li>
                <img src="images/class1.jpg" />
                <div class="text-con">
                    <p class="title">标题</p>
                </div>
            </li>
        </ul>
    </div>
</div>

第三步,写css代码

<style>
body,p,ul,li{
    margin: 0;
    padding: 0;
}
.item-wrap .item ul {
    overflow:hidden;
}
.item-wrap .item ul li{
    width: 297px;
    height: 198px;
    position: relative;
    float: left;
    overflow:hidden;
    cursor: pointer;
}
.item-wrap .item ul li .text-con{
    width: 297px;
    height: 30px;
    background: rgba(0,0,0,.5);
    position: absolute;
    left: 0;
    bottom:0;
}
.item-wrap .item ul li .text-con .title{
    font-size: 16px;
    color: #fff;
    text-align: center;
    line-height: 30px;
}
</style>

第四步,写JQ代码

<script>
    $(".item-wrap .item ul li").hover(function() {
        /* Stuff to do when the mouse enters the element */
        $(this).find(".text-con").animate({'height': '198px'}, 300);
    }, function() {
        /* Stuff to do when the mouse leaves the element */
        $(this).find(".text-con").animate({'height': '30px'}, 300);
    });
</script>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值