有關(guān)jQuery的位置函數(shù),現(xiàn)在有:(offset(),innerWidth(),innerHeight(),outerWidth(),outerHeight(),scrollTop(),scrollLeft())等,今天小編就來介紹一下其應(yīng)用實例,下面的實例中,以“撐出滾動條”和“漂浮的廣告”作為例子,請看代碼演示:
<!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><title>jQuery的位置函數(shù)(offset(),innerWidth(),innerHeight(),outerWidth(),outerHeight(),scrollTop(),scrollLeft())小應(yīng)用</title><style type="text/css">#divShow{width:100px;height:50px;background-color:Green;display:none;}#divAd{width:100px;height:100px;background-color:Red;position:absolute;top:100px;left:100px;}</style><script type="text/javascript" src="http://www.vxbq.cn/uploads/common/jquery-1.3.2.min.js"></script><script type="text/javascript">//在文本框下方顯示一個div,類似日歷控件那樣。function showDiv(obj){jQuery("#divShow").css("left",jQuery(obj).offset().left);jQuery("#divShow").css("top",jQuery(obj).offset().top + jQuery(obj).outerHeight());jQuery("#divShow").show();}jQuery(function(){});//滾動條滾動,執(zhí)行下面的函數(shù),適合做浮動廣告jQuery(this).scroll(function(){jQuery("#divAd").css("top",100 + jQuery(document).scrollTop());jQuery("#divAd").css("left",100 + jQuery(document).scrollLeft());});</script></head><body><input type="text" value="ok" onclick="showDiv(this);" /><div id="divShow">2010-03-22</div><div id="divAd">浮動廣告<br /> 左右滾動<br />查看效果</div><div style="height:2000px;width:2000px;">用來撐出滾動條</div></body></html><br /><center>如不能顯示效果,請按Ctrl+F5刷新本頁,更多網(wǎng)頁代碼:<a href='http://www.vxbq.cn/' target='_blank'>http://www.vxbq.cn/</a></center>提示:可修改后代碼再運行!
上一篇 W3C建議的移動Web標(biāo)記語言XHTML Basic 1.1
下一篇 網(wǎng)站推廣篇:增加原創(chuàng)性可加速網(wǎng)站推廣效果
程序員人生,我編程,我富裕,記住wfuyu網(wǎng),php教程,php學(xué)習(xí),php手冊,CMS模版制作
聲明:本站大部分內(nèi)容是作者原創(chuàng),少部分收集于互聯(lián)網(wǎng)供大家一起學(xué)習(xí),原版權(quán)很多不明,如有侵權(quán)請聯(lián)系本站,謝謝!
粵ICP備14040726號-1?? 2015-2020 程序員人生 版權(quán)所有