Typeerror, Is Not A Function In Rails App
I'm quite new to js and jquery and I'm trying to do something very simple for my Rails app: I want to switch between 2 images every 3 seoncs with a fading effect. The problem is th
Solution 1:
I'm answering my own question here. @dbugger pointed out that it was a good practice to wrap functions in jquery in a document ready block. So here it is if anyone needs it:
jquery code
jQuery( document ).ready(function( $ ) {
var images = [];
images[0] = "http://localhost:3000/images/pdf_template.png";
images[1] = "http://localhost:3000/images/watermark_template.png";
var x = 0;
setInterval(displayNextImage, 3000);
functiondisplayNextImage() {
x = x < images.length - 1 ? x : 0;
$("#img").fadeOut(300, function(){
$(this).attr('src', images[x]).fadeIn(300);
})
x++;
}
});
As you can see, the only change here is the addition of the jQuery( document ).ready(function( $ ) {});
block.
Post a Comment for "Typeerror, Is Not A Function In Rails App"