本文實例講述了jQuery實現DIV響應鼠標滑過由下向上展開效果。分享給大家供大家參考,具體如下:
鼠標浮動時div由下向上緩慢展開效果
1. 演示效果(鼠標浮動時div由下向上展開,浮動后div由上向下折疊恢復原樣)
2. 代碼
<!doctype html><html><head><meta charset="utf-8"><title>www.49028c.com jQuery響應鼠標實現div由下向上展開</title><style type="text/css"> .big{position:relative; width:234px; height:300px; background:#ccc} .show{position:absolute; display:none; bottom:0px;display:block; width:100%; height:auto; background:#f66 }</style><script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script><script type="text/javascript">$(document).ready(function() { $(".big").hover(function () { $(".show").stop(true,true).animate({height:"70px"}); }, function () { $(".show").stop(true,true).animate({height:"0px"}); });});</script></head><body> <!--灰色的div--> <div class="big"> <!--紅色的div--> <div class="show"></div> </div></body></html>
原理:
① 首先紅色div是通過position:absolute
絕對定位的,且通過相對與底部定位,如bottom:0px
。
② 底部定位固定,高度變高的時候就向上擴展了。
③ 使用jQuery的$().animate()
動畫方法,控制紅色div高度變化。
更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery切換特效與技巧總結》、《jQuery動畫與特效用法總結》、《jQuery擴展技巧總結》、《jQuery常用插件及用法總結》、《jQuery常見經典特效匯總》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答