本文實(shí)例講述了jquery實(shí)現(xiàn)仿新浪微博帶動(dòng)畫效果彈出層代碼。分享給大家供大家參考。具體如下:
這是一款jquery實(shí)現(xiàn)帶動(dòng)畫的彈出層,最開始是模擬新浪微博中的彈出層,后來引入了jQuery,又想了想,加入點(diǎn)動(dòng)畫效果不知怎么樣,后來就寫出了這么一個(gè)彈出的網(wǎng)頁層效果,你點(diǎn)擊按鈕后就可以看到一個(gè)漸出的可關(guān)閉的彈出層,點(diǎn)擊關(guān)閉后,當(dāng)然也是漸漸的消失的,移動(dòng)時(shí)根據(jù)鼠標(biāo)位置計(jì)算控件左上角的絕對(duì)位置,松開鼠標(biāo)后停止移動(dòng)并恢復(fù)成不透明。
運(yùn)行效果截圖如下:

在線演示地址如下:
http://demo.VeVB.COm/js/2015/jquery-f-sina-flash-style-close-able-dlg-demo/
具體代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script src="jquery-1.6.2.min.js" type="text/javascript"></script><style type="text/css">#t{ margin:30px 0 0 100px;}.cc { border:1px solid #000; position:absolute; top:60px; left:180px; height: 150px; width: 300px; display:none;}.cc h2{ display:block; width:270px; font-size:12px; float:left; text-align:center;}.cc span{ display:block; width:20px; height:20px; font-size:18px; float:right; border:1px solid #F00; background:#999; text-align:center;}</style><script language="javascript">$(function(){ var _move=false;//移動(dòng)標(biāo)記 var _x,_y;//鼠標(biāo)離控件左上角的相對(duì)位置 $('#t').click( function(){ $('.cc').fadeIn('slow'); }); $('.cc span').click(function(){ $('.cc').hide('fast'); }) $('.cc').mousedown(function(e){ _move=true; _x=e.pageX-parseInt($(".cc").css("left")); _y=e.pageY-parseInt($(".cc").css("top")); $(".cc").fadeTo(20, 0.5).css('cursor','move');//點(diǎn)擊后開始拖動(dòng)并透明顯示 }); $('.cc').mousemove(function(e){ if(_move){ var x=e.pageX-_x;//移動(dòng)時(shí)根據(jù)鼠標(biāo)位置計(jì)算控件左上角的絕對(duì)位置 var y=e.pageY-_y; $(".cc").css({top:y,left:x});//控件新位置 } }).mouseup(function(){ _move=false; $(".cc").fadeTo("fast", 1).css('cursor','auto');//松開鼠標(biāo)后停止移動(dòng)并恢復(fù)成不透明 });});</script><title>新浪微博的彈出層效果</title></head><body><input id="t" name="1" type="button" value="彈出層" /><div class="cc"><h2>點(diǎn)擊可以拖拽哦</h2><span>X</span></div></body></html>希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注