background-check icon indicating copy to clipboard operation
background-check copied to clipboard

Doesn't seem to work

Open jonaswannfors opened this issue 5 years ago • 2 comments

I get no errors in console but no action from the plugin either. At http://cinemafrica.se/ I have added the class "target" to the fixed header, and added it when I initialize the script right before

: document.addEventListener('DOMContentLoaded', function () { BackgroundCheck.init({ targets: '.target', }); });

Is there a way to know if it is working other than watching the element for added classes? Any suggestions how to solve this?

jonaswannfors avatar Sep 11 '19 12:09 jonaswannfors

After a lot of debbugging I found out that responsive images (picture, srcset) are the cause of this. I managed to fix it by changing the drawImage function to:

` function drawImage(image) { var area = getArea(image);

image = image.nodeType ? image : image.img;

if (area.imageWidth > 0 && area.imageHeight > 0 && area.width > 0 && area.height > 0) {
	/*context.drawImage(image,
                    area.imageLeft, area.imageTop, area.imageWidth, area.imageHeight,
                    area.left, area.top, area.width, area.height);*/
	//Fix for srcset images
	context.drawImage(image,
		area.left, area.top, area.width, area.height);
} else {
  log('Skipping image - ' + image.src + ' - area too small');
}

}`

jonaswannfors avatar Sep 20 '19 08:09 jonaswannfors

Make sure picture element is display: block as well to make it work, and add class to img inside it.

jonaswannfors avatar Sep 20 '19 08:09 jonaswannfors