導航:首頁 > 編程語言 > javascript浮動窗口

javascript浮動窗口

發布時間:2023-04-10 03:37:01

1. 什麼叫浮動窗口

一般激春說來,用於彈出、可移動的獨立窗口、frame、div等類似實現提塵鉛梁示、通告等功能,通稱為「浮動窗口」派運

2. javascript 關於浮動窗口

設置你的浮動窗口的style="position : relative; left: ?px; top: ?px;"

3. 浮動窗口的代碼 (html/js

第一種方法:
Html代碼
<html>
<head>
<title>浮動窗口</title>
<link type="text/css" rel="stylesheet" href="css/overflow.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/overflow.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var b = $("#b");
var overFlow = $("#over");
b.click(function(){
overFlow.fadeIn();
$("#mask").css("background","#111");
$("#mask").css("opacity","0.8");
})
$("#close").click(function(){
overFlow.fadeOut();
$("#mask").css("background","#fff");
$("#mask").css("opacity","1");
});
drag($("#over"),$("#title"));
}) ;
</script>
</head>
<body>
<div id="over">
<div id="title"><span id="t">這只是一個演示標題</span><span id="close">[ x ]</span></div>
<div id="content">
When a container object, such as a div, has mouse capture, events originating on objects within that container are fired by the div, unless the bContainerCapture parameter of the setCapture method is set to false. Passing the value false causes the container to no longer capture all document events. Instead, objects within that container still fire events, and those events also bubble as expected.<br/>
---This is edited by Alp.
</div>
</div>
<div id="mask"> <a id="b" href="#">click</a></div>
</body>
</html>

Js代碼
function drag(overFlow,title){
title.onmousedown = function(evt){
var doc = document;
var evt = evt || window.event;
var x = evt.offsetX?evt.offsetX:evt.layerX;
var y = evt.offsetY?evt.offsetY:evt.layerY;
if(overFlow.setCapture){
overFlow.setCapture();
}else if(window.captureEvents){
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
}
doc.onmousemove = function(evt){
evt = evt || window.event;
var xPosition = evt.pageX || evt.clientX;
var yPosition = evt.pageY || evt.clientY;
var newX = xPosition - x;
var newY = yPosition - y;
overFlow.style.left = newX;
overFlow.style.top = newY;
};
doc.onmouseup = function(){
if(overFlow.releaseCapture){
overFlow.releaseCapture();
}else if(window.captureEvents){
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
}
doc.onmousemove=null;
doc.onmouseup=null;
};
};
}

css代碼
#over{
position: absolute;
left: 300px;
top: 200px;
border: 1px solid black;
display: none;
background: #cccccc;
cursor: default;
width: 300px;
z-index: 10;
opacity: 1;
}
#title{
border: 1px solid #1840C4;
background: #95B4DC;
padding: 2px;
font-size:12px;
cursor: default;
}
#close{
cursor: pointer;
margin-right: 1px;
overflow: hidden;
}
#content{
border: 1px solid #C2D560;
background: #EFF4D7;
}
#t{
margin-right:145px;
}
#mask{
z-index: 1;
background: #fff;
width: 1024px;
height: 800px;
}
#b{
position: absolute;
left: 200px;
top: 100px;
}
body{
padding: 0px;
margin: 0px;
}
#over{
background: transparent;
}

第二種方法:
消息框遮罩層:<iframe id="show_upload_iframe" frameborder=0 scrolling="no" style="display:none; position:absolute;"></iframe><div id="show_upload">nothing...</div>'

頁面載入loading中:<div id="body_loading" onClick="loaded();"><img src="__PUBLIC__/images/body_load.gif"></div>

關閉浮動窗口:<a href="javascript:hideupload()">關閉窗口建議用小圖片</a>

打開浮動窗口:<a href="javascript:showupload('admin.php')">打開浮動</a>
// 消息框loading
function loading(){
var o = $('#body_loading');
o.css("left",(($(document).width())/2-(parseInt(o.width())/2))+"px");
o.css("top",(($(document).height()+$(document).scrollTop())/2-(parseInt(o.height())/2))+"px");
o.fadeIn("fast");
}
// 消息框消失
function loaded(){
var o = $('#body_loading');
o.fadeOut("fast");
}
// 隱藏浮動窗口
function hideupload(){
$('#show_upload').hide();
$('#show_upload_iframe').hide();
}
// 彈出浮動窗口
function showupload(ajaxurl){
loading();
var o=$('#show_upload');
var f=$('#show_upload_iframe');
var top = 200;
$.ajax({
url: ajaxurl,
//cache: false,
success: function(res){
loaded();
o.html(res);
o.css("left",(($(document).width())/2-(parseInt(o.width())/2))+"px");
if($(document).scrollTop()>200){
top = ($(document).height()+$(document).scrollTop())/2-(parseInt(o.height())/2);
}
o.css("top",top+"px");
f.css({'width':o.width(),'height':o.height(),'left':o.css('left'),'top':o.css('top')});
f.show();
o.show();
}
});
}

4. 網頁中如何加入懸浮窗口能一直懸浮在瀏覽器某個地方的。

1、首先創建一個名為「topwindows.html」的網頁文件,其中的內容將被展示主頁浮動窗口中。

2、網頁浮動窗口對應的部分代碼如下所示:
<html>
<style>
.img_wd{
font-size:30;padding-top:20px;
text-align:left;padding-left:70px;line-height:40px;
background:url(110.jpg) top center no-repeat;
width:252px;height:127px;line-heiht:10px;
text-align:center;
font-family:"微軟雅黑,仿宋,楷體,黑體"
color: #fafafa;
text-shadow : rgba(255,255,255,0.5) 0 5px 6px, rgba(255,255,255,0.2) 1px 3px 3px;
}
</style>
<body>
<div class="img_wd" style="">
青春就是這么任性!<Br>
Younger GOOD
</div>
</body>
</html>
3、接著將如圖所示的代碼添加到主頁<Body>和</Body>之間:
其中標簽"fdck」中的屬性SRC指向浮動窗口的網頁地址。

<div id="img" style="position: absolute;visibility :hidden;padding:0px;" onmouseover="clearInterval(interval)" onmouseout="interval = setInterval('changePos()', delay)" align="middle">
<span style="CURSOR:hand;color:red;font-weight:bold;font-align:center;font-size:12px;padding-left:0px;" onclick="clearInterval(interval);fdck.style.visibility = 'hidden';img.style.visibility = 'hidden';">隱藏</span>
<div id="fdck" style="width:100%; height:100%; font-align:center; visibility:visible;border:0px; background-color: no">
<iframe width=320 height=150 src="topWindows.html" frameborder=no scrolling="no">
</iframe>
</div>
</div>
4、接下來需要添加浮動窗口隨時運行的行為,對應代碼如下:
<script language=javascript>
var xPos = 20;
var yPos = document.body.clientHeight;
var step = 1;
var delay = 30;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
img.style.top = yPos;
function changePos() {
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = img.offsetHeight;
Woffset = img.offsetWidth;
img.style.left = xPos + document.body.scrollLeft;
img.style.top = yPos + document.body.scrollTop;
if (yon) {yPos = yPos + step;}
else {yPos = yPos - step;}
if (yPos < 0) {yon = 1;yPos = 0;}
if (yPos >= (height - Hoffset)) {yon = 0;
yPos = (height - Hoffset);}
if (xon) {xPos = xPos + step;}
else {xPos = xPos - step;}
if (xPos < 0) {xon = 1;xPos = 0;}
if (xPos >= (width - Woffset)) {xon = 0;xPos = (width - Woffset);}
}
function start() {
img.style.visibility = "visible";
interval = setInterval('changePos()', delay);}
start();
</script>

5、在此需要說明一點,需要將以上所有代碼(包括JS腳本)全部放置在<body>和</body>之間。

6、最後查看一下浮動窗口的效果,會發現浮動窗口在網頁中不斷的移動,當滑鼠懸停其上時會停止移動,點擊「隱藏」按鈕將自動隱藏懸浮窗口。

5. 如圖,如何在網頁中用Javascript實現該圖片沿窗口四周循環浮動,求詳細代碼

<!DOCTYPEhtml>
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>_</title>
<styletype="text/css">
,body{margin:0;padding:0;height:100%;}
#img1{position:absolute;}
</style>
<scriptsrc="http://libs..com/jquery/1.11.1/jquery.min.js"></script>
</head>
<scripttype="text/javascript">
$(function(){
vardir=1,size=10,interval=30;
varwidth=$(document.body).width(),height=$(document.body).height();
varimg=$("#img1"),w=img.width(),h=img.height(),offset=img.offset();

setInterval(function(){
switch(dir){
case1:
offset.left+=size;
if(offset.left+w>=width){
offset.left=width-w;
dir++;
}
break;
case2:
offset.top+=size;
if(offset.top+h>=height){
offset.top=height-h;
dir++;
}
break;
case3:
offset.left-=size;
if(offset.left<=0){
offset.left=0;
dir++;
}
break;
case4:
offset.top-=size;
if(offset.top<=0){
offset.top=0;
dir++;
}
break;
}
if(dir>4){
dir=1;
}
img.offset(offset);
},interval);

$(window).resize(function(){
width=$(document.body).width();
height=$(document.body).height();
});
});
</script>
<body>
<imgid="img1"src="star.jpg"/>
</body>
</html>

6. JSP中怎麼實現點擊鏈接然後出現浮動的窗口

那個只是js打開div的效果,和struts2無關。
<a href="javascript:show()" >打開窗口</a>
<div id="d1" style="display:none;">內容</div>
<script>
var show=function(){
document.getElementById("d1").style.display="";
}
</scirpt>
當然我這個是最簡單的功能示例。

7. javascript如何實現彈出浮動窗口

<html>
<head>
<title>Js彈出浮動窗口,支持滑鼠拖動和關閉</title>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<scripttype="text/javascript">
/**
關於一些參數說明:
*bodycontent:要在窗口顯示的內容,dom對象
*title:窗口標題,字元串類型
*removeable:窗口能否拖動,布爾類型
*注意:內容窗體的高度是height-30px,請計算好你要顯示的內容的高度和寬度。彈出窗的id為"223238909",所以你的頁面不要再取值為"223238909"的id了,以防js執行出錯*/
functioncreatedialog(width,height,bodycontent,title,removeable){
if(document.getElementById("www_phpstudy_net")==null){
/*創建窗口的組成元素*/
vardialog=document.createElement("div");
vardialogtitlebar=document.createElement("div");
vardialogbody=document.createElement("div");
vardialogtitleimg=document.createElement("span");
vardialogtitle=document.createElement("span");
vardialogclose=document.createElement("span");
varcloseaction=document.createElement("button");
/*為窗口設置一個id,id如此怪異是為了盡量避免與其他用戶取的id相同而出錯*/
dialog.id="223238909";
/*組裝對話框標題欄,按從里到外的順序組裝*/
dialogtitle.innerHTML=title;
dialogtitlebar.appendChild(dialogtitleimg);
dialogtitlebar.appendChild(dialogtitle);
dialogtitlebar.appendChild(dialogclose);
dialogclose.appendChild(closeaction);
/*組裝對話框主體內容*/
if(bodycontent!=null){
bodycontent.style.display="block";
dialogbody.appendChild(bodycontent);
}
/*組裝成完整的對話框*/
dialog.appendChild(dialogtitlebar);
dialog.appendChild(dialogbody);
/*設置窗口組成元素的樣式*/
vartempleft,temptop,tempheight//窗口的位置(將窗口放在頁面中間的輔助變數)
vardialogcssText,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;";
/*為窗口元素注冊事件*/
vardialogleft=parseInt(dialog.style.left);
vardialogtop=parseInt(dialog.style.top);
varismousedown=false;//標志滑鼠是否按下
/*關閉按鈕的事件*/
closeaction.onclick=function(){
dialog.parentNode.removeChild(dialog);
}
/*實現窗口的移動,這段代碼很典型,網上很多類似的代碼*/
if(removeable==true){
varismousedown=false;
vardialogleft,dialogtop;
vardownX,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;
}
}
returndialog;
}//endif(if的結束)
}
</script>
<style>
table{background:#b2d235;}
button{font-size:12px;height:23;background:#ece9d8;border-width:1;}
#linkurl,#linkname,#savelink{width:100px;}
</style>
</head>
<body>
<!--顯示窗口的地方-->
<divid="here"></div><aid="clickhere"href="#">點擊生成窗口</a>
<!--要嵌入到窗口的內容-->
<divid="login"style="display:none;">
<formaction="#"method="post"onSubmit="returnfalse;">
<tablewidth="400"height="95">
<tr>
<tdwidth="78">鏈接文字</td>
<tdwidth="168"><inputname="link.name"type="text"/></td>
<tdwidth="138"id="linktext"></td>
</tr>
<tr>
<td>鏈接地址</td>
<td><inputname="link.url"type="text"/></td>
<tdid="linkurl"></td>
</tr>
<tr>
<td></td>
<td><buttontype="submit"style="float:right;">添加</button></td>
<tdid="savelink"></td>
</tr>
</table>
</form>
</div>
<scripttype="text/javascript">
varhere=document.getElementById("here");
varlogin=document.getElementById("login");
varclickhere=document.getElementById("clickhere");
clickhere.onclick=function(){
here.appendChild(createdialog(400,95+30,login,"歡迎光臨phpstudy",true));
}
</script>
</body>
</html>

8. Javascript按鈕點擊浮動窗口,需要能在父窗口的范圍內隨機移動(不超出父窗口的位置范圍)

按照如下修敗讓閉改函察裂數b應該就可以了
function b(){
new_screenX = window.screenX + Math.random()*(800-200);
new_screenY = window.screenY + Math.random()*(600-200);
window.open("b.html","浮動窗口滑答","toolbar=1, location=1, status=0, menubar=1,width=200,height=200,screenX="+new_screenX+",screenY="+new_screenY);
}

9. 怎樣用javascript實現帶關閉窗口的浮動廣告

首先浮動的窗口就是一個層,在這個層上放置一個小的層,代表關閉按鈕,可以使用背景圖片內,或者img,用小層裝容,是為來方便固定位置,在這個小層中可以寫js代碼,當滑鼠點擊是獲得大層,修改大層的隱藏屬性,這樣就實現來,整個層的關閉

10. 求問JAVASCRIPT如何製作網頁浮動小窗口

靜態的你會寫吧?先把靜態的寫出來,再根據你點擊的更多信息的項目來確定彈窗中的展示內容。關閉按鈕用一個圖片,給它設置點擊事件,點擊它的時候整個彈窗隱藏。

閱讀全文

與javascript浮動窗口相關的資料

熱點內容
maya粒子表達式教程 瀏覽:84
抖音小視頻如何掛app 瀏覽:283
cad怎麼設置替補文件 瀏覽:790
win10啟動文件是空的 瀏覽:397
jk網站有哪些 瀏覽:134
學編程和3d哪個更好 瀏覽:932
win10移動硬碟文件無法打開 瀏覽:385
文件名是亂碼還刪不掉 瀏覽:643
蘋果鍵盤怎麼打開任務管理器 瀏覽:437
手機桌面文件名字大全 瀏覽:334
tplink默認無線密碼是多少 瀏覽:33
ipaddgm文件 瀏覽:99
lua語言編程用哪個平台 瀏覽:272
政采雲如何導出pdf投標文件 瀏覽:529
php獲取postjson數據 瀏覽:551
javatimetask 瀏覽:16
編程的話要什麼證件 瀏覽:94
錢脈通微信多開 瀏覽:878
中學生學編程哪個培訓機構好 瀏覽:852
榮耀路由TV設置文件共享錯誤 瀏覽:525

友情鏈接