jsp中:
目前創(chuàng)新互聯(lián)公司已為近1000家的企業(yè)提供了網(wǎng)站建設、域名、虛擬空間、網(wǎng)站托管、服務器租用、企業(yè)網(wǎng)站設計、浦城網(wǎng)站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
body
div style="position: absolute;z-index:90" id="div1"我不動/div
div我動div
/body
//有的將position設置成fixed,我試了試效果不如position好,設置z-index,向里的深度,我這兒設置90,你要覆蓋幾個div,設置數(shù)大于那個數(shù)就行。
js中:
我這兒用jquery寫。
$(document).ready(function(){
$(window).scroll(function(){//滾動時觸發(fā)函數(shù)
$("#div1").css("top",$(document).scrollTop());//將滾動條高度賦給懸浮框。
})
})
導入jquery庫,效果就出來了。
寫一個全屏的透明層,再寫上一個懸浮窗口,點擊按鈕的時候透明層和懸浮窗都顯示,用戶就只能操作你的懸浮窗口了,代碼自己寫
html
head
titleJs彈出浮動窗口,支持鼠標拖動和關閉/title
meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/
script?type="text/javascript"
/**
關于一些參數(shù)說明:
*bodycontent:要在窗口顯示的內(nèi)容,dom對象
*title:窗口標題,字符串類型
*removeable:窗口能否拖動,布爾類型
*注意:內(nèi)容窗體的高度是height-30px,請計算好你要顯示的內(nèi)容的高度和寬度。彈出窗的id為"223238909",所以你的頁面不要再取值為"223238909"的id了,以防js執(zhí)行出錯*/
function?createdialog(width,height,bodycontent,title,removeable){
if(document.getElementById("www_phpstudy_net")==null){
/*創(chuàng)建窗口的組成元素*/
var?dialog?=?document.createElement("div");
var?dialogtitlebar=?document.createElement("div");
var?dialogbody?=?document.createElement("div");
var?dialogtitleimg?=?document.createElement("span");
var?dialogtitle?=?document.createElement("span");
var?dialogclose?=?document.createElement("span");
var?closeaction?=?document.createElement("button");
/*為窗口設置一個id,id如此怪異是為了盡量避免與其他用戶取的id相同而出錯*/
dialog.id?=?"223238909";
/*組裝對話框標題欄,按從里到外的順序組裝*/
dialogtitle.innerHTML?=?title;
dialogtitlebar.appendChild(dialogtitleimg);
dialogtitlebar.appendChild(dialogtitle);
dialogtitlebar.appendChild(dialogclose);
dialogclose.appendChild(closeaction);
/*組裝對話框主體內(nèi)容*/
if(bodycontent!=null){
bodycontent.style.display?=?"block";
dialogbody.appendChild(bodycontent);
}
/*組裝成完整的對話框*/
dialog.appendChild(dialogtitlebar);
dialog.appendChild(dialogbody);
/*設置窗口組成元素的樣式*/
var?templeft,temptop,tempheight//窗口的位置(將窗口放在頁面中間的輔助變量)
var?dialogcssText,dialogbodycssText;//拼出dialog和dialogbody的樣式字符串
templeft?=?(document.body.clientWidth-width)/2;
temptop?=?(document.body.clientHeight-height)/2;
tempheight=?height-30;
dialogcssText=?"position:absolute;background:#65c294;padding:1px;border:4px;top:"+temptop+"px;left:"+templeft+"px;height:"+height+"px;width:"+width+"px;";
dialogbodycssText?=?"width:100%;background:#ffffff;"+"height:"?+?tempheight?+?"px;";
dialog.style.cssText?=?dialogcssText;
dialogtitlebar.style.cssText?=?"height:30px;width:100%;background:url(images/titlebar.png)?repeat;cursor:move;";
dialogbody.style.cssText??=?dialogbodycssText;
dialogtitleimg.style.cssText?=?"float:left;height:20px;width:20px;background:url(images/40.gif);"+"display:block;margin:4px;line-height:20px;";
dialogtitle.style.cssText?=?"font-size:16px;float:left;display:block;margin:4px;line-height:20px;";
dialogclose.style.cssText??=?"float:right;display:block;margin:4px;line-height:20px;";
closeaction.style.cssText?=?"height:20px;width:24px;border-width:1px;"+"background-image:url(images/close.png);cursor:pointer;";
/*為窗口元素注冊事件*/
var?dialogleft?=?parseInt(dialog.style.left);
var?dialogtop?=?parseInt(dialog.style.top);
var?ismousedown?=?false;//標志鼠標是否按下
/*關閉按鈕的事件*/???????
closeaction.onclick?=?function(){
dialog.parentNode.removeChild(dialog);
}
/*實現(xiàn)窗口的移動,這段代碼很典型,網(wǎng)上很多類似的代碼*/
if(removeable?==?true){
var?ismousedown?=?false;
var?dialogleft,dialogtop;
var?downX,downY;
dialogleft?=?parseInt(dialog.style.left);
dialogtop?=?parseInt(dialog.style.top);
dialogtitlebar.onmousedown?=?function(e){
ismousedown?=?true;
downX?=?e.clientX;
downY?=?e.clientY;
}
document.onmousemove?=?function(e){
if(ismousedown){
dialog.style.top?=?e.clientY?-?downY?+?dialogtop?+?"px";
dialog.style.left?=?e.clientX?-?downX?+?dialogleft?+?"px";
}
}
/*松開鼠標時要重新計算當前窗口的位置*/
document.onmouseup?=?function(){
dialogleft?=?parseInt(dialog.style.left);
dialogtop?=?parseInt(dialog.style.top);
ismousedown?=?false;
}
}
return?dialog;?
}//end?if(if的結(jié)束)
}
/script
style
table{background:#b2d235;}
button{font-size:12px;height:23;background:#ece9d8;border-width:1;}
#linkurl,#linkname,#savelink{width:100px;}
/style
/head
body
!--?顯示窗口的地方?--
div?id="here"/diva?id="clickhere"?href="#"點擊生成窗口/a
!--?要嵌入到窗口的內(nèi)容?--
div?id="login"?style="display:none;"
form?action="#"?method="post"?onSubmit="return?false;"
table?width="400"?height="95"
tr
td?width="78"鏈接文字/td
td?width="168"input?name="link.name"?type="text"http://td
td?width="138"?id="linktext"/td
/tr
tr
td鏈接地址/td
tdinput?name="link.url"?type="text"http://td
td?id="linkurl"/td
/tr
tr
td/td
tdbutton?type="submit"?style="float:right;"添加/button/td
td?id="savelink"/td
/tr
/table
/form
/div
script?type="text/javascript"
var?here?=?document.getElementById("here");
var?login?=?document.getElementById("login");
var?clickhere?=?document.getElementById("clickhere");
clickhere.onclick?=?function(){
here.appendChild(createdialog(400,95+30,login,"歡迎光臨phpstudy",true));
}
/script
/body
/html
點擊參數(shù)調(diào)用圖進行查詢即可。在浮窗菜單欄也可更加快捷的顯示查詢結(jié)果。
文章標題:javascript浮窗,網(wǎng)頁浮窗怎么做
鏈接URL:http://chinadenli.net/article0/dsdsdio.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供面包屑導航、網(wǎng)站設計公司、搜索引擎優(yōu)化、做網(wǎng)站、Google、用戶體驗
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)