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

Multiple instances #3

Closed
mkdizajn opened this issue Apr 16, 2020 · 2 comments
Closed

Multiple instances #3

mkdizajn opened this issue Apr 16, 2020 · 2 comments

Comments

@mkdizajn
Copy link

mkdizajn commented Apr 16, 2020

Hi,

thank you for your little and great library..

I have one quick question, how would I add multiple masonry grids (each with its own set of rules.. gutter, width etc..) and one thing,, I can only use one class (for ex. .masonry) but I guess I need to document.querySelectorAll('.masonry') iterate each node right?

Thanks

@mkdizajn
Copy link
Author

Ok, got it,, I've found solution to have multiple instances just by having same class starting with .masonry[XX] and easily hook that to DOM loaded evt and all sparky now :) Please close this as it's fixed now

	var arr = document.querySelectorAll( '[class^="masonry"]' ) ;
	if( arr.length ){
		for (var i = arr.length - 1; i >= 0; i--) {
			var data = JSON.parse( arr[i].dataset.mason );
			var masonry = new MiniMasonry({
			  container: '.' + arr[i].classList[0],
			  baseWidth: parseInt( data.width ),
			  gutter: parseInt( data.gap )
			});			
		}
	}

@Spope
Copy link
Owner

Spope commented Apr 16, 2020

Ok nice solution.

@Spope Spope closed this as completed Apr 16, 2020
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

2 participants