博客列表 >20.jQuery hover使用注意事项以及折叠框布局-2019年01月29号

20.jQuery hover使用注意事项以及折叠框布局-2019年01月29号

万物皆对象
万物皆对象原创
2019年02月14日 16:56:44787浏览

实例

<!DOCTYPE html>

<html>

<head>

    <meta charset="utf-8">

    <title>折叠盒子</title>

    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

    <style type="text/css">

        *{margin: 0; padding: 0;}

        li{

            list-style-type: none;

            width: 232px;

            height: 172px;

            background: lightblue;

            border-radius: 8px;

            position: relative;

            overflow: hidden;

            float: left;

            margin: 15px;

        }

        li img{

            width: 232px;

            height: 124px;

        }

        li a{

            text-decoration: none;

        }

        .title{

            background: blue;

            border-radius: 8px;

            width: 232px;

            height: 144px;

            position: absolute;

            top: 90px;

        }

        .total{

            background: green;

            border-radius: 8px;

            width: 232px;

            height: 42px;

            line-height: 42px;

            position: absolute;

            bottom: 0;

        }

        .total span{

            font-size: 12px;

            color: #fff;

        }

    </style>

<script type="text/javascript">

    $(document).ready(function(){

        $('a').hover(function(){

            // 这里注意事项:如果没有加find()方法无论你鼠标移入那个都好

            // 会导致全部'.title'有动画效果的,加上find()解决此问题

            $(this).find('.title').stop().animate({top:'30px'});

        },function(){

            $(this).find('.title').stop().animate({top:'90px'});

        });

    });

</script>

</head>

<body style="background:#ccc;">

        <ul>

            <li>

                <a href="" class="aa">

                    <img src="https://img.php.cn/upload/course/000/126/153/5aa23f0ded921649.jpg">

                    <div class="title" id="t">

                        <h3>内容1

                            <p>内容2</p>

                        </h3>

                    </div>

                    <div class="total">

                        <span>4153人在看</span>

                    </div>

                </a>

            </li>



            <li>

                <a href="">

                    <img src="https://img.php.cn/upload/course/000/126/153/5aa23f0ded921649.jpg">

                    <div class="title" id="t">

                        <h3>内容1

                            <p>内容2</p>

                        </h3>

                    </div>

                    <div class="total">

                        <span>3493人在看</span>

                    </div>

                </a>

            </li>

        </ul>

</body>

</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

6666.jpg

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议