Change div class on scroll

Everything to do with Joomla! 3.x templates and templating.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
Donethat
Joomla! Explorer
Joomla! Explorer
Posts: 434
Joined: Fri May 30, 2008 12:36 pm
Location: Redhill
Contact:

Change div class on scroll

Post by Donethat » Mon Apr 20, 2015 10:21 am

I want to be able to change the class of a div on page scroll. Once the class changes then any number of things can be achieved.

For the time being I want to stick the menu to the top and modify other aspects of it's styling. I have tried any number of versions of jQuery scripts for doing this and in isolation, i.e. a non Joomla page with nothing else on it these nearly all work fine with most versions of jQuery.

The problems arise as soon as I try and use it on a Joomla template. Currently using a blank from blank.vc

I am a great fan of these blank templates so I'm hoping there is something I am missing in this

This is the current test page

http://lawandorderfoundation.org

The Javascript I am using on this page is

Code: Select all

$(window).scroll(function() {
  if ($(document).scrollTop() > 10) {
    $('nav').addClass('shrink');
  } else {
    $('nav').removeClass('shrink');
  }
});
Perfection is a state of mind, not reality
www.cavespider.co.uk

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2887
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Change div class on scroll

Post by SharkyKZ » Tue Apr 21, 2015 7:34 am

Maybe your site is running jQuery in noconflict mode? In that case changing $ to jQuery in your code or creating a different alias should fix this https://api.jquery.com/jquery.noconflict/.

Donethat
Joomla! Explorer
Joomla! Explorer
Posts: 434
Joined: Fri May 30, 2008 12:36 pm
Location: Redhill
Contact:

Re: Change div class on scroll

Post by Donethat » Tue Apr 21, 2015 8:00 am

Thank you for responding

I discovered that no conflict mode is a problem and I'm not using it.

I'll check out the link.

Cheers

Crispin
Perfection is a state of mind, not reality
www.cavespider.co.uk


Locked

Return to “Templates for Joomla! 3.x”