最近在瀏覽網頁時,看到一些圖片,鼠標一放上去呢,就會有說明文字「浮」上來,移開又「沉」下去,感受好炫!本身就在網上找實現代碼啊,看看事件是怎麼實現的!而後就找到了以下的代碼:javascript
恩呢,放在編譯器裏,的確有效果,的確是我想象中的那樣,但是,我本身感受寫的太複雜了,挺簡單的一個問題對吧?而後就本身寫了,剛開始有點小問題,不知道怎麼實現那個上浮效果,最後想到了overflow這個屬性,寫出瞭如下代碼:css
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="content-type" content="txex/html charset=utf-8" >
- <script src="jquery-1.11.1.js"></script>
- <style type="text/css">
- body{
-
- font-family: simhei;
- }
- p{
- color: #ffffff;
- }
- div{
- overflow: hidden;
- }
- </style>
- <script type="text/javascript">
- $(document).ready(function(){
-
- $(".pic").mouseover(function()
-
-
- { $(".he").animate({top:'280px'},500);})
-
- $(".pic").mouseout(function()
-
- {$(".he").animate({top:'330px'},500);}
- )
- });
- </script>
- </head>
- <body>
- <div style="position: relative">
- <img src="test.png" class="pic">
- <div style="width:231px;height: 50px;background-color: orange;position: absolute;top:330px" class="he">
- <p align="center" >開始答題</p>
- </div>
- </div>
- </body>
- </html>