MyBB Community Forums

Full Version: [PAID] jQuery help – change element style when bottom viewport hits element
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
(2013-03-05, 09:08 PM)brad-t Wrote: [ -> ]Will try it when I have some time – thank you!!

No Problem Smile

(2013-03-05, 09:08 PM)Euan T. Wrote: [ -> ]You could do, yes. But it's easier to just use the built in methods which do exactly that behind the scenes.

Very true. I was thinking more of the lines of code readability. However, what you did looks fine as well, just maybe not in a "it does this exactly" sort of way. Once again, thanks for the corrections.
Just hope it works now Wink I just edited my above post with a version using (document).ready() as it makes the code slightly neater. It's the version I'd personally prefer if it works.
(2013-03-05, 09:14 PM)Euan T. Wrote: [ -> ]Just hope it works now Wink I just edited my above post with a version using (document).ready() as it makes the code slightly neater. It's the version I'd personally prefer if it works.

Yeah, I agree. It makes it look a lot neater. Like I said, I'm not a huge fan of javascript, so when I saw the (document).ready(), it made me cringe a bit.
Still not working for me. None of this. Sincerely starting to wonder if there's some weird conflict or something preventing this from working.
Any chance I can get a temp account to take a look and play in the console?
sure, will PM you details
Finally got this working, so I'll share the code that ended up working:

jQuery.noConflict();

jQuery(window).scroll(function() {
	var myElt        = jQuery('#hidecontrol'); // whatever element you want to check
	var thewindow    = jQuery(window); // the window jQuery element
	var myTop        = myElt.offset().top; // the top (y) location of your element
	var windowTop    = thewindow.scrollTop(); // the top of the window
	var windowBottom = windowTop + thewindow.height(); // the bottom of the window

	if ((myTop > windowTop && myTop < windowBottom)) {
	    jQuery('#control_menu').fadeOut(); // Fade out the element because the element we're checking is in view
	} else {
	    jQuery('#control_menu').fadeIn(); // Fade the element back in
	}
});
I really hope someone else will find this useful. Thanks so much!!
Pages: 1 2 3