代码之家  ›  专栏  ›  技术社区  ›  tessa

需要关于jquery插件圆角的建议吗

  •  5
  • tessa  · 技术社区  · 16 年前

    我想学习jquery插件,所以我决定尝试制作一个简单的圆角框。我知道已经有一些圆角插件在那里,但这对我来说更多的是一个学习练习,而不是一个工作要求。

    我取的圆角 here . 我喜欢这个样品,因为它不使用图像,它将很容易改变盒子的颜色。

    我想我很难用最好的方法来解决这个问题。我有一个非常粗糙的样品,这是一种工作,但它只是不觉得正确。最让我头疼的是在内容区域周围构建圆角。现在它接受“内容”框并在其周围添加角。有什么更好的方法?

    下面是对box-$('#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>
    
    5 回复  |  直到 16 年前
        1
  •  2
  •   Gordon Gustafson    16 年前

    http://www.curvycorners.net/ http://www.curvycorners.net/

    javascript库,不是jQuery插件,但它似乎可以工作:D

        2
  •  1
  •   Josh    16 年前
        3
  •  1
  •   zooglash    16 年前

    这个很好:

    http://jrc.rctonline.nl/

    它使用帆布,所以非常灵活。

        4
  •  1
  •   Adam A    14 年前

    您可以将title和separator设置为函数的选项,而不是附加到#fundingAdminContainer,您可以这样做

    outer.insertBefore($(this));
    

    在将$(this)附加到outer之前。

    编辑:这个答案现在已经过时了。现在大多数浏览器都支持通过CSS border radius属性或至少一个特定于浏览器的选项来实现圆角。我还想说,在大多数情况下,为不支持CSS的旧浏览器多填充圆角甚至不值得额外的js(当然这是我的观点)。所以如果我要给出一个完整的答案,我会说只要使用 this 照它说的做:)。

    但是如果你真的想要你的圆角在<IE9,我建议 this

    this . htc只是JS。这将减轻IE9对JS-DOM的操作。

        5
  •  0
  •   Sumith Harshan    11 年前

    这个 jQuery转角插件 可能会有帮助。简单易用,令人惊叹。

    http://jquery.malsup.com/corner/

    $('#myDiv').corner();