Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroy option #32

Open
invasoria opened this issue Jan 27, 2018 · 1 comment
Open

Destroy option #32

invasoria opened this issue Jan 27, 2018 · 1 comment

Comments

@invasoria
Copy link

Hi,
Is there a way to destroy a fit.js object so I can keep things clean and save some memory? I'm using multiple calls to fit images into div containers but once I remove those images I'd like to get rid of listeners.

@invasoria
Copy link
Author

invasoria commented Jan 29, 2018

Ok. The thing is I'm using the same container for multiple dynamic images so every time a new image is loaded and placed I would need fit.js to, well, fit that new image into the old container. So, while thinking of re-usability I messed up with the code a little, like this:

transform.trigger = function(newtarget) {
  if (newtarget!== undefined) {
      target = newtarget;
  }
  fit( target, container, options, callback, transform );
};

This way I can store just one fit.js method and trigger it any time I want and use new things as targets, replacing/updating the old one:

var IMAGE = document.getElementById('image');
var CONTAINER = document.getElementById('container-div');

var watching = fit(IMAGE, CONTAINER);

and then update and replace like this once the new image/thingy is available:

var NEW_IMAGE = document.getElementById('new-image');
watching.trigger(NEW_IMAGE);

I don't know if this modification is beneficial and I'd like to know what you think about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant