I'm building a site on wordpress and using javascript to create a particle-slider image for the business logo. I'm switching between the particle-slider version and a static image for the logo with a switch point at 960px. I'va had major issues with the re-sizing as documented here and here . I've now got it to work with help from those answers, however, its still a bit clunky especially on Safari where I'm getting the following error on the console when the page re-sizes -
It also ocassionally throws up this error in chrome -
This is the javascript code in my page -
particle-slider.php
<script type="text/javascript">
var ps = null
function init(){
var isVisible = window.innerWidth >= 960;
if (!ps && isVisible) {
// create and init
ps = new ParticleSlider({
// ptlGap: 1,
// ptlSize: 1,
width: 1400,
height: 600,
});
ps.init(false);
} else if (ps && !isVisible) {
// stop and remove
ps.requestAnimationFrame = function() {}; // Stop render loop
ps = null;
}
}
window.addEventListener('load', init, false)
window.onload = init;
window.addEventListener('resize', init, false);
window.onresize = init;
</script>
Can anyone spot what might be throwing up this error? Is it in this script or in the particle-slider javascript file?
Is it possible to apply a try/catch code block to prevent these errors? If that's the case how would I go about this? (I'm not that well versed with javascript so would appreciate any assistance).