2

I am developing an android app with the cordova framework and I want to change the background color of my header panel depending on the scroll position. The problem is that the scroll event never get fired, neither in my emulator nor on the device.

An attempt with Angular:

app.directive("scroll", function ($document) {
        return {
            restrict: 'A',
            link: function (scope, element, attrs) {
                console.log("scroll initiated");
                $document.bind('scroll', function () {
                    console.log("scrolling ...");
                });
            }
        };
    })

An attempt with jQuery: ​

$(document).ready(function() {
    $(window).on('scroll', function() {
        console.log('scrolling ...');
    });
}

I also implemented this jsfiddle example in my app, but it didn't work ...

Can anyone help me to solve my problem ?

4
  • 1
    Please read the documentation! You have to wait for the cordova deviceready event.
    – Joerg
    Oct 7, 2015 at 20:12
  • function onLoad() { document.addEventListener("deviceready", onDeviceReady, false); } function onDeviceReady() { $(document).ready(function () { $(window).on('scroll', function () { console.log('scrolling ...'); }) }); } It's still not working.
    – thoss
    Oct 8, 2015 at 15:18
  • You likely want the Statusbar Plugin. You also want to read Top Mistakes by Developers new to Cordova/Phonegap
    – user3255670
    Oct 10, 2015 at 8:29
  • @katzu, plz provide the solution if you have fixed it. (I am using custom directive way to fix a row on top while scrolling down) Aug 6, 2016 at 15:36

1 Answer 1

0

i'm on Cordova using android and with jquery i use:

 $(window).scroll(function() 
   {
     ...
   }

and it works, tell me if it worsk even for you.

3
  • i've also created a method that fetch data and dynamically create and remove elements depending from the data i load, the pain was to set well the scroll focus.
    – Lorenzo
    Oct 16, 2015 at 10:20
  • The code is working but the event is not firing anyway because of some onsen-ui css styling ... i tried to remove the css file and it worked. but i dont know exactly what css is preventing the event to fire.
    – thoss
    Oct 17, 2015 at 15:50
  • the only property in css that makes me think of scrolling is overflow (w3schools.com/cssref/css3_pr_overflow-x.asp)...but i'm not sure if it is the only one
    – Lorenzo
    Oct 19, 2015 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.