首页 > PHP资讯 > HTML5培训技术 > jquery自定义插件——window的实现【示例代码】_jquery

jquery自定义插件——window的实现【示例代码】_jquery

HTML5培训技术
本例子实现弹窗的效果:

1、jquery.show.js

/*  * 实现功能:点击在鼠标位置显示p  * 版本序号:1.0  */(function($){   $.fn.showDIV = function(options){     var defaults = {};     var options = $.extend(defaults, options);     var showp=$(this);     var close, title, content;     close=$(" 

"); title=$(" "); content=$(" "); showp.html(""); showp.append(close); showp.append(title); showp.append(content); close.html("X"); title.html(options.title); content.html(options.content); showp.css("display","block"); showp.css("position","absolute"); showp.css("left",($(window).width()-options.width)/2+"px"); showp.css("top",($(window).height()-options.height)/2+"px"); showp.css("width",options.width); showp.css("height",options.height); close.bind("click",function(){ showp.css("display","none"); }); }; })(jQuery);

2、jquery.showp.css

body p {   font-size:12px;   text-align:center; } #container {   background-color:#CCC;   border:1px solid #000;   width:1024px;   height:600px; } #showp {   background-color:#FF0;   width:100px;   height:100px;   display:none;   z-index:99; } .title {   padding:10px;   background:#F39;   font-weight:bold;   text-align:center;   color:#FFF; } .close {   margin:5px;   position:absolute;   right:0px;   top::0px;   padding:5px;   color:#000;   background:#FFF; } .close:hover {   cursor:pointer;   background:#CCC; } .content {   text-align:left;   padding:10px; }

3、demo.html

<script type="text/javascript" src="jquery/jquery.min.js?1.1.15">《script》 <script type="text/javascript" src="jquery/jquery.showp.js?1.1.15">《script》 <script type="text/javascript">   $(document).ready(function (){      $('#show').bind("click", function(evt){       var showp = $('#showp').showDIV({         width:400,         height:200,         title:"我不是黄蓉",         content:"我不是黄蓉
我不会武功
我只要靖哥哥
完美的爱情" }); }); }); 《script》

实现后的效果如下:

以上这篇jquery自定义插件——window的实现【示例代码】就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

HTML5培训技术

本文由欣才IT学院整理发布,未经许可,禁止转载。
支持34不支持0