[英]How to call function on 'mixEnd' after filter has been applied in MixItUp jQuery plugin?
Desired Behaviour 期望的行为
I am wanting to call a custom function after mixItUp
has finished performing its filter function. 我想在
mixItUp
完成其过滤功能后调用自定义函数。
MixItUp
is evoked on selecting a value from a dropdown. 从下拉列表中选择一个值会引起
MixItUp
。
Current Behaviour 当前行为
To demonstrate and test functionality I am calling alert()
on mixEnd
. 为了演示和测试功能,我在
mixEnd
上调用alert()
。
The number of times the alert box shows after selecting a value is incrementing on each subsequent selection, ie after the first selection it shows once, after the second selection it shows twice. 在选择一个值后,警报框显示的次数在每个后续选择中递增,即在第一次选择后显示一次,在第二次选择后显示两次。
jQuery jQuery的
//define function
function initFilters() {
$('#container').mixItUp({
layout: {
display: 'block'
},
animation: {
duration: 1000,
effects: 'translateZ(-360px) stagger(110ms) fade',
easing: 'ease'
}
});
}
// call function
initFilters();
// define .on behavior
$('#area_filter, #rating_filter').on('change', function () {
$('#container').mixItUp('filter', this.value);
// do something on mixEnd
$('#container').on('mixEnd', function(e, state){
alert('MixItUp finished!');
});
});
jsFiddle jsFiddle
http://jsfiddle.net/rwone/e3c6x29f/ http://jsfiddle.net/rwone/e3c6x29f/
Steps To Reproduce 重现步骤
Question 题
There are a number of approaches to applying multiple functions and callbacks in MixItUp
which are shown below. 有许多方法可以在
MixItUp
应用多个函数和回调,如下所示。
My questions are therefore: 因此,我的问题是:
How do I resolve the undesired behaviour of the alert box showing incrementally? 如何解决增量显示警报框的不良行为?
Which of the following approaches is the most elegant way to achieve the desired behaviour (as I suspect my current approach is causing the problem)? 以下哪种方法是实现所需行为的最优雅的方法(因为我怀疑当前的方法正在引起问题)?
Options 选件
multiMix ( https://mixitup.kunkalabs.com/docs/#method-multiMix ) multiMix ( https://mixitup.kunkalabs.com/docs/#method-multiMix )
Example: 例:
$('#container').mixItUp('multiMix', {
filter: '.category-1, .category-2',
sort: 'name:asc',
changeLayout: {
containerClass: 'flex'
}
});
callback with onMixEnd ( https://mixitup.kunkalabs.com/docs/#prop-callbacks-onMixEnd ) 使用onMixEnd进行回调 ( https://mixitup.kunkalabs.com/docs/#prop-callbacks-onMixEnd )
$('#container').mixItUp({
callbacks: {
onMixEnd: function(state){
alert('Operation ended');
}
}
});
And there is also a example of this approach (which I am currently using): 还有这种方法的示例(我目前正在使用):
$('#container').on('mixEnd', function(e, state){
alert('MixItUp finished!');
});
Well here is one solution, still not sure if most elegant though, but it solves the undesired multiple triggering behaviour. 好了,这是一个解决方案,虽然仍然不确定是否最优雅,但是它解决了不希望的多重触发行为。
All I had to do was move the .on('mixEnd', function(e, state)
out of the dropdown select area like so: 我要做的就是将
.on('mixEnd', function(e, state)
移出下拉选择区域,如下所示:
//define function
function initFilters() {
$('#container').mixItUp({
layout: {
display: 'block'
},
animation: {
duration: 1000,
effects: 'translateZ(-360px) stagger(110ms) fade',
easing: 'ease'
}
});
}
// do something on mixEnd <-- added here
$('#container').on('mixEnd', function(e, state){
alert('MixItUp finished!');
});
// call function
initFilters();
// define .on behavior
$('#area_filter, #rating_filter').on('change', function () {
$('#container').mixItUp('filter', this.value);
// <-- removed from here
});
jsFiddle jsFiddle
http://jsfiddle.net/rwone/e3c6x29f/8/ http://jsfiddle.net/rwone/e3c6x29f/8/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.