简体   繁体   English

刷新,刷新,取消绑定,摧毁,生活,使用Javascript / jQuery函数...应该如何进行?

[英]reload, refresh, unbind, destroy, live, javascript/jquery function… how should this be done?

My question title may seem confusing, let explain my situation. 我的问题标题似乎令人困惑,让我们解释一下我的情况。 Any help would be much appreciated. 任何帮助将非常感激。


I have never done this before, hence why I can't pin point a solution in google. 我以前从未做过此事,因此为什么我无法在Google中指出解决方案。

I have a jquery slideshow, which I wrapped inside a function because I have some addition animation to go with it, please see below... 我有一个jquery幻灯片,我将其包装在一个函数中,因为我还有一些其他动画,请参见下面的内容...

// my slider function
bikeSlider = function () {

    var slider = $('#bike-minislider').bxSlider({

        displaySlideQty: 5,
        infiniteLoop: false,
        hideControlOnEnd: true                      

    });

    $('#bike-minislider-fade').fadeIn();

};

// this runs the function
bikeSlider();

As you can see, immediately after the bikeSlider function, I run the function using... bikeSlider(); 如您所见,在bikeSlider函数之后,我立即使用... bikeSlider();运行该函数bikeSlider();

Now later on, I hide some slides within the slideshow using jquery .hide() . 现在稍后,我使用jquery .hide()在幻灯片中隐藏一些幻灯片

Because my jquery slideshow function, calculates the number of visible slides within the #bike-minislider div, it means that the new number of visible slides causes the slideshow to not work. 由于我的jquery幻灯片显示功能可计算#bike-minislider div中可见幻灯片的数量,因此这意味着新的可见幻灯片数量导致幻灯片无法正常工作。 I guess it needs to re-calculate the new number of slides. 我想它需要重新计算新的幻灯片数量。

In a nutshell, I think this can be resolved by running the bikeSlider(); 简而言之,我认为可以通过运行bikeSlider();来解决此问题bikeSlider(); function again. 再次起作用。

So I tried this below, but it did not work. 因此,我在下面尝试了此操作,但没有成功。

bikeFilter = function (y) {

    $('.bike').fadeOut();
    $('.bike[data-group=' + y + ']').fadeIn();

    bikeSlider();

    return false;

}

As you can see I am trying to re-run the function bikeSlider(); 如您所见,我正在尝试重新运行功能bikeSlider(); - but it seems to be running this over the top of the old one, so my question is, how do you remove the original slide function before running it again. -但它似乎是在旧版本之上运行的,所以我的问题是,如何在再次运行之前删除原始幻灯片功能。

Or reloading/refreshing the original function so it re-calculate the new number slides? 还是重新加载/刷新原始功能,以便重新计算新的数字幻灯片?


Any pointers would be so helpful. 任何指针都将非常有帮助。

Thank You. 谢谢。

As i understood you dont need re-create slider, but you do exectly this by calling twice 据我了解,您不需要重新创建滑块,但是您可以通过调用两次来明确地做到这一点

bxSlider()

According doc you need reinit slider by 根据文档,您需要通过以下方式重新启动滑块

reloadShow()
//Reinitialize a slide show

For more info take a look here bxslider in section Public functions 有关更多信息,请在公共功能部分中查看bxslider

You need to call reloadShow() for slider-object 您需要为滑块对象调用reloadShow()

var mySlider;
$(function(){
    mySlider= $('#bike-minislider').bxSlider({
        auto: true,
        controls: true
    });

    mySlider.reloadShow();
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM