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

Lavalamp not updating on scroll #1

Closed
yoxalld opened this issue Feb 7, 2014 · 1 comment
Closed

Lavalamp not updating on scroll #1

yoxalld opened this issue Feb 7, 2014 · 1 comment

Comments

@yoxalld
Copy link

yoxalld commented Feb 7, 2014

Hi,

I am trying to get the lavalamp effect to update as the page scrolls into different sections. I have the 'active' class changing on each li element as the page scrolls using the code below. But for some reason the lavalamp plugin isn't updating it's position.

var sections = $('.menu-update'),

        links = $('#menu-main li');

        $(window).scroll(function() {

            var currentPosition = $(this).scrollTop();

            sections.each(function() {

                var top = $(this).offset().top,

                    bottom = top + $(this).height();

                if (currentPosition >= top && currentPosition <= bottom) {

                    links.removeClass('active');

                    $('a[href="#' + this.id + '"]').parent().addClass('active');

                }

            });

        });

Is there a way to force lavalamp to update? Maybe something like

$('#menu-main').lavalamp('update');

Thanks!

@Richard1320
Copy link
Owner

The plugin only looks for the active class when it is first initiated. Updated in 1.0.4, You can now manually send the active element to the wrapper data.

Instead of:

$('a[href="#' + this.id + '"]').parent().addClass('active');

Bind it to the "active" data of the main element and then update.

var a = $('a[href="#' + this.id + '"]').parent();
$('#menu-main').data('active',a).lavalamp('update');

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