jQuery Background Canvas transparency

梦想与她 提交于 2020-01-05 04:31:38

问题


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;
}

回答1:


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

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



回答2:


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.



来源:https://stackoverflow.com/questions/2389217/jquery-background-canvas-transparency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!