youtube / spfjs

A lightweight JS framework for fast navigation and page updates from YouTube
https://youtube.github.io/spfjs/
MIT License
2.23k stars 147 forks source link

jquery function is not working after loading with ajax #436

Open recruitname opened 7 years ago

recruitname commented 7 years ago

On my web page, everything is okay.

My js is working very well but clicking on any page, page is loading with ajax but some function is not working for example my bootstrap carousel or my parallax.js plugin..

How do I do event management ?

some js example on my page

`if (!$(".scene").length) return false; var q = document.getElementsByClassName("scene")[0]; var r = new Parallax(q, { calibrateX: false, calibrateY: true, invertX: false, invertY: true, limitX: false, frictionX: .2, frictionY: 4, originX: 0, originY: 1 });

$('.img-area').cycle({ fx: 'fadeout', speed: 950, timeout: 100 }).cycle("pause");

$(".otel-history-list").on("click",function(){

var historyName = $(this).find(".history-current-name").text();
var historyDateIn = $(this).find(".history-current-datein").text();
var historyDateOut = $(this).find(".history-current-dateout").text();
var historyKisi = $(this).find(".history-current-kisi").text();

$(".input-form-ara input").val(historyName);
$(".otel-giris-cikis #checkin").val(historyDateIn);
$(".otel-giris-cikis #checkout").val(historyDateOut);
$(".kisi-sayi-otel-sec .kisi-count").text(historyKisi);

});`

and my spf code

`$(function () { spf.init(); NProgress.configure({ showSpinner: false });

$(document).on('spfrequest', function (event) {
    NProgress.set(0.4);
});

$(document).on('spfprocess', function (event) {
    NProgress.set(0.6);
    NProgress.set(0.8);
});

$(document).on('spfdone', function (event) {
    NProgress.set(1.0);
    NProgress.done();

});

$(document).on('spfhistory', function (event) {
    NProgress.set(0.7);
    NProgress.set(0.9);
    NProgress.set(1.0);
    NProgress.done();

});

});`

VarinderS commented 7 years ago

It could be because .scene div and .img-area divs are getting replaced by the new ajax content?

If that is the case, you may want to re-initalize parallax cycle plugin inside of spfdone event...