经过来回的寻找,我发现我错过了
relatedTarget.id
所以我用这个switch语句来完成它,我相信上面的答案也是有办法的,但这对我来说很有效:
$('#startPageCarousel').on('slide.bs.carousel', function (ev) {
var id = ev.relatedTarget.id; // needed to get the id of the element
switch (id) {
case "3":
// do something the id is 3
var options = {
ââuseEasing: true,
ââuseGrouping: true,
ââseparator: ',',
ââdecimal: '.',
};
var stat1 = new CountUp('stats1', 0, numberOfPosts, 0, 5.5, options);
var stat2 = new CountUp('stats2', 0, numberOfPosts, 0, 5.5, options);
var stat3 = new CountUp('stats3', 0, numberOfPosts, 0, 5.5, options);
var stat4 = new CountUp('stats4', 0, numberOfPosts, 0, 5.5, options);
if (!stat1.error && !stat2.error && !stat3.error && !stat4.error) {
ââstat1.start();
stat2.start();
stat3.start();
stat4.start();
}
break;
}
});