user1433479
user1433479

Reputation: 135

JQuery not executing in Cordova

I'm working on a mobile app using Cordova. There is a page where I want to have a JQuery slider. To achieve this I'm using the popular swipe.js, which I'm calling like so: <script src="js/swipe.js"></script>

However when I emulate the app and go to the page it just shows me the static HTML. Even weirder, when I put the WWW in MAMP and run it in the browser it also shows me static HTML untill I refresh the page once, after which it runs as I want it to.

I'm using deviceready but it doesn't seem to help much:

document.addEventListener("deviceready", function(){
    Slider = $('#slider').Swipe({
        auto: 1000,
        continuous: true
    }).data('Swipe');

    $('#share-button').click(function() {
        $('#social').css('display', 'block');
        $('#overlay').css('display', 'block');
    });

    $('#overlay').click(function() {
        $('#social').css('display', 'none');
        $('#overlay').css('display', 'none');
    });
},true);

I set the timer to 1000ms so I can see if the jquery is working or not.

Upvotes: 0

Views: 214

Answers (2)

Asanka Indrajith
Asanka Indrajith

Reputation: 353

Instead of document.addEventListener use jQuery pageshow event to initialize Swipe Slider. http://www.w3schools.com/jquerymobile/event_pageshow.asp

Upvotes: 2

Kris Georgiev
Kris Georgiev

Reputation: 140

1.Always use deviceready with cordova you.

2.Make sure you have all the javascript need cordova,cordova_plugins,jquery,swipe ect.

3.Make sure it actually deviceready is firing.

This is how i do it

 $(document).ready( function() {
       document.addEventListener("deviceready", controller.StartApp, false);
   });
controller.StartApp = function()
{
alert("Device ready");
}

Upvotes: 0

Related Questions