Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Jonathan Grieve
Jonathan Grieve
91,254 Points

Adapting a Sticky Plugin

Hello Treehouse'ers once again :)

I have a rather crude looking website that I made today to test the Sticky plugin for the jQuery plugins course. It has the same code and the HTML from what I can tell is strucuted the same way.

http://www.jonniegrieve.co.uk/jg-lab.co.uk/treehouse/sites/sticky/index.html

But it doesn't quite work the way it's supposed to.

The first problem is that it doesn't seem to work with a top spacing setting or less than 1 which is what i want, ideally.

$('.sticky-element').sticky({   

        topSpacing: 1
});
/**/

Secondly I'd like know why the visual behaviour of the green bar seems to work as it should but ther HTML contained in the 'sticky-end' function doesn't change back to the text I want. It seems to default to <p>Ooooh, look at me go</p>' and I can't understand why.

Here's the html and JS.

        <header class="header">
            <h2 class="sticky-element">Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit<br />
            Using the Sticky plugin... watch how this sticks</h2>
        </header>
$('.header').on('sticky-start', function() {

    $('.sticky-element').html('<p>Ooooh, look at me go</p>');

});

$('.header').on('sticky-end', function() {

    $('.sticky-element').html('<h2 class="sticky-element">Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit<br />Using the Sticky plugin... watch how this sticks</h2>');
});