Prevent some elements from being rendered canvas

Geatrix picture Geatrix · Dec 19, 2014 · Viewed 9.7k times · Source

This is my website I want the background of my nav-element to be blurred.. I used html2canvas and stackblur for this, 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 its only working in wekit browsers, because i dont know how to add multiple properties to

"-webkit-transform",

Thanks in advance. 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>

Answer

Guilherme Nascimento picture Guilherme Nascimento · Jan 1, 2015

I found in html2canvas updates this Added support for "data-html2canvas-ignore" attribute

For prevent render a DOM element, you need put 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>