简体   繁体   English

用jQuery流畅圆角

[英]Fluid rounded corners with jQuery

What is the best way to create fluid width/height rounded corners with jQuery? 使用jQuery创建流体宽度/高度圆角的最佳方法是什么?


That plugin doesn't keep the height the same. 该插件不保持高度相同。 I have a 10px high div that I want to round the corners on, when I use that script it adds about 10px onto whats there. 我有一个10px高的div,我想绕过角落,当我使用那个脚本时,它会增加大约10px到那里。

I use: Jquery-roundcorners-canvas 我使用: Jquery-roundcorners-canvas

it handles borders, and keeps things the same size, in fact you have to pad in a bit to keep from having letters live in the crease. 它处理边框,并保持相同的大小,实际上你必须填补一点,以防止在折痕中存在字母。 Its pretty fast, unless you are on ie 6. Same pretty syntax of the other corner packs, but just prettier in general. 它非常快,除非你在使用ie 6.其他角落组合的相同漂亮的语法,但一般来说更漂亮。

Edited to add new link for jQuery Roundcorners Canvas 编辑为jQuery Roundcorners Canvas添加新链接

The way the jQuery UI Theming API accomplishes this in Firefox is with " Corner Radius Helpers ". jQuery UI Theming API在Firefox中实现这一点的方式是“ Corner Radius Helpers ”。

Here's what they look like in the CSS that was bundled in my copy of the UI: 这是他们在我的UI副本中捆绑的CSS中的样子:

/* Corner radius */
.ui-corner-tl { -moz-border-radius-topleft: 4px; -webkit-border-top-left-radius: 4px; }
.ui-corner-tr { -moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; }
.ui-corner-bl { -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px; }
.ui-corner-br { -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; }
.ui-corner-top { -moz-border-radius-topleft: 4px; -webkit-border-top-left-radius: 4px; -moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; }
.ui-corner-bottom { -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; }
.ui-corner-right {  -moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; }
.ui-corner-left { -moz-border-radius-topleft: 4px; -webkit-border-top-left-radius: 4px; -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px; }
.ui-corner-all { -moz-border-radius: 4px; -webkit-border-radius: 4px; }

Unfortunately, these don't appear to have any effect in IE7 as of this post. 不幸的是,这篇文章在IE7中似乎没有任何影响。

In jQuery code, one of these classes might be applied in a fashion something like this: 在jQuery代码中,这些类中的一个可能以这样的方式应用:

$('#SomeElementID').addClass("ui-corner-all");

If you want full control about the border an d gradient, you can use my iQuery Background Canvas plugin. 如果你想完全控制边框和渐变,你可以使用我的iQuery Background Canvas插件。 It works with a HTML5 Canvas element and allows to draw borders and backgrounds in any variation. 它适用于HTML5 Canvas元素,允许在任何变体中绘制边框和背景。 But you should be able to program JavaScript 但是你应该能够编写JavaScript

This is a full featured sample with a background gradient and rounded corners. 这是一个功能齐全的样本,背景渐变和圆角。 as you can see, the drawing is completely done in JavaScript, you can set every parameter you want. 如您所见,绘图完全在JavaScript中完成,您可以设置所需的每个参数。 The drawing is redone on every resize (Due to the resize Event), you can adapt the background drawing to show wat you want on this specific size. 每次调整大小时都会重新绘制图形(由于调整大小事件),您可以调整背景图形以在此特定大小上显示所需的视图。

$(document).ready(function(){
    $(".Test").backgroundCanvas();
});

function DrawBackground() {
    $(".Test").backgroundCanvasPaint(TestBackgroundPaintFkt);
}
// Draw the background on load and resize
$(window).load(function () { DrawBackground(); });
$(window).resize(function() { DrawBackground(); });

function TestBackgroundPaintFkt(context, width, height, elementInfo){
    var options = {x:0, height: height, width: width, radius:14, border: 0 };
    // Draw the red border rectangle
    context.fillStyle = "#FF0000";
    $.canvasPaint.roundedRect(context,options);
    // Draw the gradient filled inner rectangle
    var backgroundGradient = context.createLinearGradient(0, 0, 0, height - 10);
    backgroundGradient.addColorStop(0 ,'#AAAAFF');
    backgroundGradient.addColorStop(1, '#AAFFAA');
    options.border = 5;
    context.fillStyle = backgroundGradient;
    $.canvasPaint.roundedRect(context,options);
}

Here is the plugin, and this site makes a vast use of it: jQuery Background Canvas Plugin 这是插件,这个网站大量使用它: jQuery Background Canvas插件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM