I am new, please be gentle. I've reviewed these posts on using the jquery .scroll() event, but haven't had luck implementing a working fix.
http://stackoverflow.com/questions/5686629/jquery-window-scroll-event-does-not-fire-up
http://stackoverflow.com/questions/19375636/jquery-onscroll-not-firing-the-event-while-scrolling
I am working on a site that uses Jquery Mobile. I've included a small script to produce a parallax effect on background images when the user vertically scrolls the page. It is written as such:
$(window).on('scroll', function(){
$('.slider').each(function(r){
var pos = $(this).offset().top;
var scrolled = $(window).scrollTop();
$('.slider').css('background-position-y', -(scrolled * 0.3) + 'px');
});
});
This code works wonderfully when I enter it in the console after the page has loaded. It does nothing when loaded as part of my custom script. It is located at the end of my main.js file which is the last .js referenced in my HTML, immediately after the JQM CDN distribution link.
...</body>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src='js/buildpage.js'></script>
<script src="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.js"></script>
<script src='js/main.js'></script>
</html>
I've tried a $(windows).scroll(function(){alert('scroll')})
in lieu of my parallax script, which results in a single alert as the page is resized when JQM initializes and modifies the layout, then nothing further. Re-entering the line in the console after page load results in alerts when the window is scrolled.
If I comment out the JQM link, the parallax script works just fine.
In summary: Parallax script is dependant on .scroll().
Parallax script is the last line in the last .js referenced in the HTML.
Parallax script does not work if loaded inline with the referenced scripts.
Parallax script works fine if entered in the dev console after the page has loaded (Chrome).
Disabling JQM results in the desired effect... but now JQM is off! :(
Thank you in advance for your guidance and sagely wisdom.