开发者

jQuery Background Canvas transparency

开发者 https://www.devze.com 2022-12-22 05:32 出处:网络
I\'m using the jQuery Background Canvas plugin and have created a DIV with rounded corners and a gradient effect. However, I\'m unable to get the transparency to work. What am I doing wrong? Here\'s t

I'm using the jQuery Background Canvas plugin and have created a DIV with rounded corners and a gradient effect. However, I'm unable to get the transparency to work. What am I doing wrong? Here's the JavaScript:

$(document).ready(function()
{
$(".Test").backgroundCanvas();
$(".Test").makeElementTransparent("#CECFCE");
$(".Test").backgroundCanvas(true, "#CECFCE");
});

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:7, border: 0 };
// Draw the red border rectangle
context.fillStyle = "#CECFC6";
$.canvasPaint.roundedRect(context,options);
// Draw the gradien开发者_如何学编程t filled inner rectangle
var backgroundGradient = context.createLinearGradient(0, 0,
0, height - 10);
backgroundGradient.addColorStop(0 ,'#F7F7EF');
backgroundGradient.addColorStop(1, '#CECFCE');
options.border = 1;
context.fillStyle = backgroundGradient;
$.canvasPaint.roundedRect(context,options);
}

The element itself looks like this:

<div class="Test">
   something here
</div>

And here's the CSS for it:

.Test {
    width: 300px;
    height: 300px;
}


I ran into the same problem. In my case, the following line did the trick:

$('#*[canvasId]*').css('background-color','transparent');


The solution has nothing to do with this jQuery library; it's the opacity/transparency CSS attributes. For Firefox and Safari, this does the trick:

.Test {
   -moz-opacity:0.5; /* For older FF versions */
   -khtml-opacity:0.5;
   opacity:0.5;
}

For IE, this was necessary:

canvas.jbgCanvas {
   filter:alpha(opacity=50);
}

In most cases, you should be able to apply the filter attribute to your element; but in this case, the only way it worked was to apply it to the CANVAS object.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号