Note. I am not familiar with the Javascript helper library you are using.
I assume that you need to change the two lines after your comment to the following:
maskEl.style.width = box.width + "px"; maskEl.style.height = box.height + "px";
source share