


jQuery realizes the floating layer prompt in the lower right corner of the web page
最近有同事提到类似网页右下角的消息悬浮提示框的制作。我之前也做过一个类似的例子,很简单。是仿QQ消息。现在感觉之前的那个例子只是说了实现原理,整体上给你的感觉还是太丑,今天为大家带来一个新的例子。是Discuz右下角悬浮层提示的。运行效果如下:
<!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>jQuery实现网页右下角悬浮层提示</title> <style type="text/css"> *{margin:0;padding:0;list-style-type:none;} a,img{border:0;} body{font:12px/180% Arial, Helvetica, sans-serif, "新宋体";} /* pop */ #pop{background:#fff;width:260px;border:1px solid #e0e0e0;font-size:12px;position:fixed;right:10px;bottom:10px;} #popHead{line-height:32px;background:#f6f0f3;border-bottom:1px solid #e0e0e0;position:relative;font-size:12px;padding:0 0 0 10px;} #popHead h2{font-size:14px;color:#666;line-height:32px;height:32px;} #popHead #popClose{position:absolute;right:10px;top:1px;} #popHead a#popClose:hover{color:#f00;cursor:pointer;} #popContent{padding:5px 10px;} #popTitle a{line-height:24px;font-size:14px;font-family:'微软雅黑';color:#333;font-weight:bold;text-decoration:none;} #popTitle a:hover{color:#f60;} #popIntro{text-indent:24px;line-height:160%;margin:5px 0;color:#666;} #popMore{text-align:right;border-top:1px dotted #ccc;line-height:24px;margin:8px 0 0 0;} #popMore a{color:#f60;} #popMore a:hover{color:#f00;} </style> </head> <body style="height:1200px;"> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript"> (function($j){ $j.positionFixed = function(el){ $j(el).each(function(){ new fixed(this) }) return el; } $j.fn.positionFixed = function(){ return $j.positionFixed(this) } var fixed = $j.positionFixed.impl = function(el){ var o=this; o.sts={ target : $j(el).css('position','fixed'), container : $j(window) } o.sts.currentCss = { top : o.sts.target.css('top'), right : o.sts.target.css('right'), bottom : o.sts.target.css('bottom'), left : o.sts.target.css('left') } if(!o.ie6)return; o.bindEvent(); } $j.extend(fixed.prototype,{ ie6 : $.browser.msie && $.browser.version < 7.0, bindEvent : function(){ var o=this; o.sts.target.css('position','absolute') o.overRelative().initBasePos(); o.sts.target.css(o.sts.basePos) o.sts.container.scroll(o.scrollEvent()).resize(o.resizeEvent()); o.setPos(); }, overRelative : function(){ var o=this; var relative = o.sts.target.parents().filter(function(){ if($j(this).css('position')=='relative')return this; }) if(relative.size()>0)relative.after(o.sts.target) return o; }, initBasePos : function(){ var o=this; o.sts.basePos = { top: o.sts.target.offset().top - (o.sts.currentCss.top=='auto'?o.sts.container.scrollTop():0), left: o.sts.target.offset().left - (o.sts.currentCss.left=='auto'?o.sts.container.scrollLeft():0) } return o; }, setPos : function(){ var o=this; o.sts.target.css({ top: o.sts.container.scrollTop() + o.sts.basePos.top, left: o.sts.container.scrollLeft() + o.sts.basePos.left }) }, scrollEvent : function(){ var o=this; return function(){ o.setPos(); } }, resizeEvent : function(){ var o=this; return function(){ setTimeout(function(){ o.sts.target.css(o.sts.currentCss) o.initBasePos(); o.setPos() },1) } } }) })(jQuery) function Pop(title,url,intro){ this.title=title; this.url=url; this.intro=intro; this.apearTime=1000; this.hideTime=500; this.delay=10000; //添加信息 this.addInfo(); //显示 this.showDiv(); //关闭 this.closeDiv(); } Pop.prototype={ addInfo:function(){ $("#popTitle a").attr('href',this.url).html(this.title); $("#popIntro").html(this.intro); $("#popMore a").attr('href',this.url); }, showDiv:function(time){ if (!($.browser.msie && ($.browser.version == "6.0") && !$.support.style)) { $('#pop').slideDown(this.apearTime).delay(this.delay).fadeOut(400);; } else{//调用jquery.fixed.js,解决ie6不能用fixed $('#pop').show(); jQuery(function($j){ $j('#pop').positionFixed() }) } }, closeDiv:function(){ $("#popClose").click(function(){ $('#pop').hide(); } ); } } </script> <script type="text/javascript" > //页面加载调用 window.onload=function(){ //使用参数:1.标题,2.链接地址,3.内容简介 new Pop("这里是标题,哈哈", "http://www.php.cn", "php中文网"); } </script> <div id="pop" style="display:none;"> <div id="popHead"> <a id="popClose" title="关闭">关闭</a> <h2 id="温馨提示">温馨提示</h2> </div> <div id="popContent"> <dl> <dt id="popTitle"><a href="www.php.cn" target="_blank">这里是标题</a></dt> <dd id="popIntro">这里是内容简介</dd> </dl> <p id="popMore"><a href="www.php.cn" target="_blank">查看 »</a></p> </div> </div> <div style="text-align:center;clear:both"> <p>php中文网</p> <p><a href="www.php.cn" target="_blank">php中文网</a></p> </div> </body> </html>

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools