cross-origin-css

/* global BackgroundCheck:false */ /* http://www.kennethcachia.com/background-check/scripts/cross-origin-css.js */ function convertImageToDataURI(img) { var canvas = document.createElement('canvas'); canvas.width = img.width; canvas.height = img.height; var ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0); return canvas.toDataURL('image/png'); } document.addEventListener('DOMContentLoaded', function () { var img = new Image(); img.setAttribute('crossorigin', ''); var background = document.querySelector('.demo-css--cross-origin'); var dataSrc = background.getAttribute('data-src'); img.onload = function () { var data = convertImageToDataURI(img); background.style.backgroundImage = 'url(' + data + ')'; // Prepare BackgroundCheck BackgroundCheck.init({ targets: '.target', images: background }); }; img.src = dataSrc; });

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.