【发布时间】:2009-06-20 01:11:10
【问题描述】:
我想学习jquery插件,所以我决定尝试做一个简单的圆角框。我知道已经有一些圆角插件,但这对我来说更像是一种学习练习,而不是工作要求。
我取自here 的圆角。我喜欢这个示例,因为它不使用图像,可以轻松更改框的颜色。
我想我在思考最好的方法时遇到了麻烦。我有一个非常粗糙的样本,它有点工作,但感觉不对。让我束手无策的部分是在内容区域周围构建圆角。现在它需要“内容”框并附加它周围的角。有什么更好的方法来做到这一点?
这是制作盒子的调用 - $('#content').roundbox();
如果这些信息还不够,请告诉我。
//
(function($)
{
jQuery.fn.roundbox = function(options)
{
var opts = $.extend({}, $.fn.roundbox.defaults, options);
var outer = $("<div>");
var topBorder = $("<b class='xtop'><b class='xb1'></b><b class='xb2'></b><b class='xb3'></b><b class='xb4'></b></b>");
var bottomBorder = $("<b class='xbottom'><b class='xb4'></b><b class='xb3'></b><b class='xb2'></b><b class='xb1'></b></b>");
var title = $("<h1>Select Funding</h1>");
var separator = $("<div></div>");
$(this).append(title);
$(this).append(separator);
var firstElement = $(this).children()[0];
if (firstElement != null)
{
title.insertBefore(firstElement);
separator.insertBefore(firstElement);
}
outer.append(topBorder);
outer.append($(this));
outer.append(bottomBorder);
$("#fundingAdminContainer").append(outer);
//Add classes
outer.addClass(opts.outerClass); //outer container
$(this).addClass(opts.contentClass); //inner content
title.addClass(opts.titleClass); //roundbox title
separator.addClass(opts.lineClass); //line below title
};
$.fn.roundbox.defaults =
{
outerClass: 'roundbox',
contentClass: 'roundboxContent',
titleClass: 'roundboxTitle',
lineClass: 'roundboxLine'
};
})(jQuery);
//CSS
.roundbox
{
float:left;
width:400px;
margin-right:20px;
}
.roundboxContent
{
display:block;
background:#ffffff;
border:0 solid #D4E2FE;
border-width:0 1px;
height:180px;
padding:10px;
}
.roundboxLine
{
background: url(../images/fundingAdmin_line.gif);
background-repeat:no-repeat;
height:5px;
}
.roundboxTitle
{
font-size:1.3em; color:#17A2D3;
}
.xtop, .xbottom {display:block; background:transparent; font-size:1px;}
.xb1, .xb2, .xb3, .xb4 {display:block; overflow:hidden;}
.xb1, .xb2, .xb3 {height:1px;}
.xb2, .xb3, .xb4 {background:#ffffff; border-left:1px solid #D4E2FE; border-right:1px solid #D4E2FE;}
.xb1 {margin:0 5px; background:#D4E2FE;}
.xb2 {margin:0 3px; border-width:0 2px;}
.xb3 {margin:0 2px;}
.xb4 {height:2px; margin:0 1px;}
盒子的最终结构应该是:
<div id="fundingAdminContainer"><!-- Not part of rounded box, just serves as a container. -->
<div class="roundbox">
<b class="xtop"><b class="xb1"></b><b class="xb2"></b><b class="xb3"></b><b class="xb4"></b></b>
<div id="content" class="roundboxContent">
<h1 class="roundboxTitle">Title</h1>
<div class="roundboxLine"></div>
//CONTENT
</div>
<b class="xbottom"><b class="xb4"></b><b class="xb3"></b><b class="xb2"></b><b class="xb1"></b></b>
</div>
</div>
【问题讨论】:
-
顺便说一句,很酷的想法。我想我要开始使用这个了...
标签: jquery css jquery-plugins