This is my website.
I want the background of my nav-element to be blurred... I used html2canvas and stackblur for this, and you can find the tutorial here.
My problem is now that I want to exclude the nav-element from being rendered in canvas, so it only shows the background when scrolling. Currently it’s only working in WebKit browsers, because I don’t know how to add multiple properties to:
"-webkit-transform",
This is my code:
<script>
$(function () {
html2canvas($("body"), {
onrendered: function (canvas) {
$("div.blurnav, div.blurnav.small").append(canvas);
$("canvas").attr("id", "canvas");
stackBlurCanvasRGB(
'canvas',
0,
0,
$("canvas").width(),
$("canvas").height(),
20);
}
});
vv = setTimeout(function () {
$("body").show();
clearTimeout(vv);
}, 200);
});
$(window).scroll(function () {
$("canvas").css(
"-webkit-transform",
"translatey(-" + $(window).scrollTop() + "px)");
});
window.onresize = function () {
$("canvas").width($(window).width());
};
$(document).bind('touchmove', function () {
$("canvas").css(
"-webkit-transform",
"translatey(-" + $(window).scrollTop() + "px)");
});
$(document).bind('touchend', function () {
$("canvas").css(
"-webkit-transform",
"translatey(-" + $(window).scrollTop() + "px)");
});
</script>
I found this in html2canvas updates: Added support for "data-html2canvas-ignore" attribute
For preventing render of a DOM element, you need add the data-html2canvas-ignore
attribute in your element:
var test = document.getElementById("test");
var content = document.getElementById("content");
test.onclick = function () {
html2canvas(content, {
"onrendered": function(canvas) {
document.body.appendChild(canvas);
}
});
};
<script src="//cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>
<p>
<a id="test" href="javascript:void(0);">test</a>
</p>
<div id="content">
<div class="element-1">1. Is visible</div>
<div class="element-2" data-html2canvas-ignore="true">2. No visible</div>
<div class="element-3">3. Is visible</div>
</div>