views:

284

answers:

1

Hi. 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 gradient 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;
}
A: 

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.

Alex