@Denzl729
Изучаю языки php js

Как заставить скрипт сработать только один раз?

$(window).scroll(function myFunction(){
if ($(window).scrollTop() >= ($(".container").offset().top - $(window).height())){
$.easing.bullshit = function myAnimation(x, t, b, c, d) {
return '(t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b';

}
$('.ach-number span').each(function myDigits() {
$(this).prop('counter', 0).animate({
counter: $(this).text(),
}, {
duration: 10000,
easing: 'bullshit',
step(val) {
$(this).text(Math.ceil(val));
},
});
});
}
})

Добрый день всем! Помогите пожалуйста! Как можно сделать чтоб скрипт отрабатывал только один раз?
  • Вопрос задан
  • 294 просмотра
Решения вопроса 1
@Denzl729 Автор вопроса
Изучаю языки php js
function start_count(){
$.easing.bullshit = function(x, t, b, c, d) {
return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
};
$('.ach-number span').each(function myDigits() {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 10000,
easing: 'bullshit',
step(val) {
$(this).text(Math.ceil(val));
}
});
});
}

document.addEventListener('scroll', function myFunction(e) {
e.preventDefault();
if($(window).scrollTop() >= ($(".container").offset().top - $(window).height())){
start_count();

document.removeEventListener("scroll", myFunction);
}
});
Решил проблему так !
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы