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

sometimes it doesn't work. #46

Open
unalignedcoder opened this issue Dec 17, 2016 · 2 comments
Open

sometimes it doesn't work. #46

unalignedcoder opened this issue Dec 17, 2016 · 2 comments

Comments

@unalignedcoder
Copy link

unalignedcoder commented Dec 17, 2016

I'm using the jquery version, and it works fine. However the functionality is intermittent.

I'm using this on a wordpress website in combination with the "Collapse O-matic" plugin which expands and collapses parts of the content, stretching the container accordingly. My function wants to stretch the sidebar as well.

What happens is that, as I expand and collapse the content area, the sidebar only grows and shrinks the first time, then it doesn't seem to respond any longer.

This is how I call the function in the footer of the page:

  jQuery(function($) {
	  
		var myFunc = function() {
		(((my function here)))
		};		
		$('#primary').resize(myFunc); 
		/*$('#primary').removeResize(myFunc); if I don't comment out this line it doesn't work altogether*/

  });

Here's the function I trigger, which is aimed at making the sidebar as long as the primary container:

var sidebar = $('.sidebar');
var contentArea = $('#primary');

if (parseInt(sidebar.outerHeight(true)) > parseInt(contentArea.outerHeight(true))) {

	sidebar.css('height',''); 

} else {

	sidebar.css('height',contentArea.outerHeight(true));
}

And this is what happens as I load the page:

jQuery(function($) {	
	$(window).on('resize load', function() {
		(((my function here)))
	});
});
@clarkk
Copy link

clarkk commented May 17, 2017

When you initiate resize it creates some DOM elements inside the element you applied resize..
Maybe you delete these elements and then it wont work anymore

@JoolsCaesar
Copy link

JoolsCaesar commented Jun 7, 2017

@clarkk is right. If (((my function here))) alters the DOM of the container too much it will stop working. Calling .html() or .empty() on the contentArea will break it. I think there might also be an issue if you set the css position to certain values.

To avoid the former you can either keep track of what elements you're putting into the contentArea with a class or something, that way you can remove them specifically and add new content using the append() function rather than html().

Or you could just add another wrapper for the content within contentArea e.g. actualContent which could be a div with width:100%:height:100%. That way you'd never mess with the contentArea div in a way that would disable the resize triggers.

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

3 participants