<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>鼠标放上去透明度和位移都变化</title> <style> * { margin:0; padding:0; } .dv1 { position: relative; left:0; top:200px; width:100px; height:300px; background-color: red; } .dv1 div { width:300px; height:300px; position: absolute; left:136px; top:0; background-color: orange; opacity: 0; } </style> </head> <body> <div class=‘dv1‘> <div></div> </div> </body> <script src=‘http://apps.bdimg.com/libs/jquery/1.8.3/jquery.min.js‘></script> <script> //这个函数里面有个坑:$(".dv1 div") . stop() 要不然只要鼠标放上去几次,函数就执行几次,这是bug,所以务必要加上这句话 $(document).ready(function(){ $(".dv1").hover(function(){ $(‘.dv1 div‘).stop().animate({ left:"120px", opacity: 1 }) },function(){ $(‘.dv1 div‘).stop().animate({ left:"300px", opacity: 0 }) }) }) </script> </html>
时间: 2024-10-12 18:58:57