Loading all jQuery variables in Doc Ready using PJax in Rails

I searched this forum and the Internet for an answer to this, but I can’t find the right solution / I don’t understand it at all ...

I previously set up the rails app to present a simple slide show. In this, I use jQuery to show the next slide by moving the container. Then I decided to implement pxax only for loading the crop, not for the full page. All this works fine except for my jQuery. I saw that if you add the on () delegate that the event works again, my initial variables for things like window = $ (window) and div = $ (div) no longer work.

$(function() {

var presentation_carousel = $('.carousel')
var carousel_width = $(".slide").length * 700;
var carousel_max_next = ((carousel_width - 700) * -1);

var view_window = $(window);
var nav_collapse = $('div.nav-collapse');

presentation_carousel.css('width', carousel_width+"px")

$('.button_next').on ('click', function(e) {
    $('.button').animate({
        opacity: 0
    }, 100)
    presentation_carousel.animate({
        'marginLeft' : "-=700px"
    }, 500, function(){
        $('.button').css('display', 'block');
        $('#quiz_carousel .button_next').css('display', 'none');

        $('.button').animate({
            opacity: 1
        }, 500)
    })
});

, div_expe_carousel . , console.log , ?

, - , pjax jQuery, , - ?

, . ... .

presentation_carousel.animate({}) 
// became
$('.carousel').animate({}) 

. Rails jQuery.

: application.html.erb . , , div.

<div class="span9">
  <div data-pjax-container>
    <%= yield %>
  </div>
</div>
+3
1

jquery-pjax events. $(document).on("pjax:end", handler) $(document).ready(handler). , .;)

+1

All Articles