Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

gareth connop
gareth connop
14,865 Points

How to change the image source using waypoints.js?

I am currently working on a project where I need to change the logo image by using waypoints.js. I have already used waypoints.js to make the header section fixed once it scrolls to the section below my banner, but now need to add in the image change.

My code:

$(function waypointTop(){
    $("#under-hero").waypoint(function(){
        $("#bluebar").toggleClass("stuck")},{offset:160})
});

In the above code the id bluebar is being given a class of stuck once it scrolls to the id under-hero, so now I just need to change the source image of #logo

Any help would be appreciated.

1 Answer

The attr method is used to access DOM element attributes. Access the "src" attributes and change the path to the image if you are using an <img> tag:

$('#logo').attr('src','path/to/image');

Otherwise, you can change the CSS background property:

$('#logo').css('background','url:(/path/to/image) auto auto');

Something along those lines.