>  기사  >  웹 프론트엔드  >  JS는 단순히 부동 창을 구현합니다.

JS는 단순히 부동 창을 구현합니다.

不言
不言원래의
2018-05-05 16:12:164075검색

이 글은 주로 JS를 이용한 플로팅 창 효과의 간단한 구현을 소개합니다. 자바스크립트가 플로팅 창을 작동시키는 생성, 열기, 닫기 및 기타 관련 조작 기술이 필요한 친구들이 참고할 수 있습니다

이 글의 예는 다음과 같습니다. JS로 부동 창 효과를 간단하게 구현합니다. 참조를 위해 모든 사람과 공유하세요. 세부 사항은 다음과 같습니다.

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>无标题文档</title>
<style type="text/css">
*{ margin:0; padding:0;}
a img{ border:0;}
</style>
</head>
<body>
<p style="height:2000px; background:#ccc; display:none;">
</p>
<!--p 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;">
<p onclick="closeFAd();" style=" width:26px; height:26px; float:right;"></p>
<p style="width:487px; height:320px; float:right;" onclick="open_online();"></p>
</p>
<p 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();></p-->
</body>
</html>
<script type="text/javascript" src="online.js"></script>

JS 부분:

// JavaScript Document
//浮动广告图片
var floatAdImg = "images/onlineSay.jpg";
//浮动侧栏图片
var floatSideImg = "images/onlineTel.gif";
//打开在线沟通
function open_online()
{
 window.open(&#39;http://p.qiao.baidu.com//im/index?siteid=7342332&ucid=7601325&#39;);
}
//浮动广告
document.writeln("<p 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("<p onclick=\"closeFAd();\" style=\" width:26px; height:26px; float:right;\"></p>");
document.writeln("<p style=\"width:487px; height:320px; float:right;\" onclick=\"open_online();\"></p>");
document.writeln("</p>");
//浮动侧栏
document.writeln("<p 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();\"></p>");
//关闭浮动广告
function closeFAd()
{
 document.getElementById(&#39;floatAd&#39;).style.display = &#39;none&#39;;
}
//打开浮动广告
function showFAd()
{
 document.getElementById(&#39;floatAd&#39;).style.display = &#39;block&#39;;
}
//打开浮动窗口
function showFloat()
{
 document.getElementById(&#39;floatAd&#39;).style.display = &#39;block&#39;;
}
//打开窗口 20 秒仅执行一次
setTimeout(showFAd,20000);
//每个 30 秒执行一次
setInterval(showFloat,30000);

렌더링은 다음과 같습니다.

관련 권장 사항:

JS 구현 동적 눈송이가 떨어지고 있습니다

캔버스 및 JS에서 동적 시계 애니메이션 구현

위 내용은 JS는 단순히 부동 창을 구현합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.