Home  >  Article  >  Web Front-end  >  jquery custom plug-in - implementation of window [sample code]_jquery

jquery custom plug-in - implementation of window [sample code]_jquery

WBOY
WBOYOriginal
2016-05-16 15:01:511606browse

This example implements the effect of a pop-up window:

1. jquery.show.js

/* 
 * 实现功能:点击在鼠标位置显示div 
 * 版本序号:1.0 
 */
(function($){ 
  $.fn.showDIV = function(options){ 
    var defaults = {}; 
    var options = $.extend(defaults, options); 
    var showdiv=$(this); 
    var close, title, content; 
    close=$(" 
"); title=$(" 
"); content=$(" 
"); showdiv.html(""); showdiv.append(close); showdiv.append(title); showdiv.append(content); close.html("X"); title.html(options.title); content.html(options.content); showdiv.css("display","block"); showdiv.css("position","absolute"); showdiv.css("left",($(window).width()-options.width)/2+"px"); showdiv.css("top",($(window).height()-options.height)/2+"px"); showdiv.css("width",options.width); showdiv.css("height",options.height); close.bind("click",function(){ showdiv.css("display","none"); }); }; })(jQuery);

2. jquery.showdiv.css

body div 
{ 
  font-size:12px; 
  text-align:center; 
} 
#container 
{ 
  background-color:#CCC; 
  border:1px solid #000; 
  width:1024px; 
  height:600px; 
} 
#showdiv 
{ 
  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"></script> 
<script type="text/javascript" src="jquery/jquery.showdiv.js"></script> 
<script type="text/javascript"> 
  $(document).ready(function (){  
    $('#show').bind("click", function(evt){ 
      var showdiv = $('#showdiv').showDIV({ 
        width:400, 
        height:200, 
        title:"我不是黄蓉", 
        content:"我不是黄蓉<BR>我不会武功<BR>我只要靖哥哥<BR>完美的爱情"
      }); 
    }); 
  }); 
</script> 
 
 
 
<INPUT id=show value=显示 type=button name=showDiv>

The effect after implementation is as follows:

The above jquery custom plug-in - the implementation of window [sample code] is all the content shared by the editor. I hope it can give you a reference, and I hope you will support Script Home.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn