Correction status:qualified
Teacher's comments:下次记得给代码加上线上运行的功能
<!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>
点击 "运行实例" 按钮查看在线实例