溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

javascript中如何實(shí)現(xiàn)浮動(dòng)窗口

發(fā)布時(shí)間:2021-06-30 11:14:18 來(lái)源:億速云 閱讀:260 作者:小新 欄目:web開(kāi)發(fā)

小編給大家分享一下javascript中如何實(shí)現(xiàn)浮動(dòng)窗口,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

javascript實(shí)現(xiàn)浮動(dòng)窗口的方法:首先創(chuàng)建HTML文件;然后通過(guò)“function showFAd(){...}”方法打開(kāi)浮動(dòng)廣告;最后通過(guò)“function showFloat(){...}”方法實(shí)現(xiàn)打開(kāi)浮動(dòng)窗口即可。

本文操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。

javascript怎么實(shí)現(xiàn)浮動(dòng)窗口?

具體如下:

HTML部分:

<!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" />
<title>無(wú)標(biāo)題文檔</title>
<style type="text/css">
*{ margin:0; padding:0;}
a img{ border:0;}
</style>
</head>
<body>
<div style="height:2000px; background:#ccc; display:none;">
</div>
<!--div id="floatAd" style=" position:fixed !important; position:absolute; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight)); z-index: 2147483647; left: 50%; margin-left: -240px !important; top: 50%; margin-top: -210px !important; background:url(images/onlineSay.jpg) no-repeat; width:487px; height:350px; cursor:pointer;">
<div onclick="closeFAd();" style=" width:26px; height:26px; float:right;"></div>
<div style="width:487px; height:320px; float:right;" onclick="open_online();"></div>
</div>
<div id="floatSide" style=" width:141px; height:579px; position:fixed !important; position:absolute; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight)); z-index: 99999; right:0; top:6%; background:url(images/onlineTel.gif);cursor:pointer;" onclick="open_online();></div-->
</body>
</html>
<script type="text/javascript" src="online.js"></script>

JS部分:

// JavaScript Document
//浮動(dòng)廣告圖片
var floatAdImg = "images/onlineSay.jpg";
//浮動(dòng)側(cè)欄圖片
var floatSideImg = "images/onlineTel.gif";
//打開(kāi)在線溝通
function open_online()
{
 window.open('http://p.qiao.baidu.com//im/index?siteid=7342332&ucid=7601325');
}
//浮動(dòng)廣告
document.writeln("<div id=\"floatAd\" style=\" position:fixed !important; position:absolute; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight)); z-index: 2147483647; left: 50%; margin-left: -240px !important; top: 50%; margin-top: -210px !important; background:url("+floatAdImg+") no-repeat; width:487px; height:350px; cursor:pointer; display:none; \">");
document.writeln("<div onclick=\"closeFAd();\" style=\" width:26px; height:26px; float:right;\"></div>");
document.writeln("<div style=\"width:487px; height:320px; float:right;\" onclick=\"open_online();\"></div>");
document.writeln("</div>");
//浮動(dòng)側(cè)欄
document.writeln("<div style=\" width:141px; height:579px; position:fixed !important; position:absolute; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight)); z-index: 99999; right:0; top:6%; background:url("+floatSideImg+");cursor:pointer;\" onclick=\"open_online();\"></div>");
//關(guān)閉浮動(dòng)廣告
function closeFAd()
{
 document.getElementById('floatAd').style.display = 'none';
}
//打開(kāi)浮動(dòng)廣告
function showFAd()
{
 document.getElementById('floatAd').style.display = 'block';
}
//打開(kāi)浮動(dòng)窗口
function showFloat()
{
 document.getElementById('floatAd').style.display = 'block';
}
//打開(kāi)窗口 20 秒僅執(zhí)行一次
setTimeout(showFAd,20000);
//每個(gè) 30 秒執(zhí)行一次
setInterval(showFloat,30000);

以上是“javascript中如何實(shí)現(xiàn)浮動(dòng)窗口”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI