Jump to content

Recommended Posts

Hi,

 

I'm wondering if anyone can help me with this one. I have a page, which dependent on the size of the browser, shows different amounts of columns.

For example if the page is 1005 pixels, it shows 3 columns, 1340 pixels, it shows 4 etc.

On each resize it resizes the header, main div and footer. All working great.

 

<script type="text/javascript">
<!--

function resetHeaderSize(){
		pages = document.getElementById('previous');
		pagesn = document.getElementById('next');

if (window.innerWidth<1341){
	topbar = document.getElementById('header');
	topbar.style.width = "985px";
	ajaxFunction();

	mainaj = document.getElementById('ajaxDiv');
	mainaj.style.width = "1005px";

	botbar = document.getElementById('footer');
	botbar.style.width = "985px";
	if (window.innerHeight<760){
		pages.style.visibility = "visible";
		pagesn.style.visibility = "visible";
		} else {
		pages.style.visibility = "hidden";
		pagesn.style.visibility = "hidden";
		}
	}
else if (window.innerWidth>=1342 && window.innerWidth<=1650){
	topbar = document.getElementById('header');
	topbar.style.width = "1320px";
	ajaxFunction();

	mainaj = document.getElementById('ajaxDiv');
	mainaj.style.width = "1340px";


	botbar = document.getElementById('footer');
	botbar.style.width = "1320px";
}
else if (window.innerWidth>1671){
	topbar = document.getElementById('header');
	topbar.style.width = "1655px";
	ajaxFunction();

	mainaj = document.getElementById('ajaxDiv');
	mainaj.style.width = "1675px";

	botbar = document.getElementById('footer');
	botbar.style.width = "1655px";
}
} 
//-->
</script>

On each 'change' of width, it also fires an ajaxrequest which is dealt with seperately. 
What i'm struggling to figure out though is how this ajaxfunction can only be fired when the width changes from one figure to the other, and not constantly when the page is being resized. I hope that makes sense? So rather than it being fired constantly, it only gets fired once the page 'jumps' between the main amounts.

Any help on this would be great!

Thanks

Edd


Link to comment
https://forums.phpfreaks.com/topic/227453-resize-after-set-size/
Share on other sites

I'm not all that familiar with how ajax requests would work, so this might not be possible, but I'll give it a go anyway.

You could store the amount of columns being displayed in a variable, and then everytime the window is resized, check to see if this amount changes, and if it does then fire the ajax request.

 

However it may not be that simple...

 

Denno

Ah I see what you mean.

I think though that the ajax request itself is irrelevant as its just a function that happens. The problem is that I only want it to fire at set pixel widths when being resized. The current code sees that the width is higher than the set amount and fires the function everytime the browser is resized. Is there a way to do it only once the criteria has been met and then thats it?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.