해당 위치에 오면 숫자가 올락라는 스크립트
본문
var isVisible = false;
$(window).on("scroll", function () {
if (checkVisible($(".up_number")) && !isVisible) {
var memberCountConTxt= 15;
$({ val : 0 }).animate({ val : memberCountConTxt }, {
duration: 2000,
step: function() {
var num = numberWithCommas(Math.floor(this.val));
$(".memberCountCon").text(num);
},
complete: function() {
var num = numberWithCommas(Math.floor(this.val));
$(".memberCountCon").text(num);
}
});
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
isVisible = true;
}
});
function checkVisible( elm, eval ) {
eval = eval || "object visible";
var viewportHeight = $(window).height(), // Viewport Height
scrolltop = $(window).scrollTop(), // Scroll Top
y = $(elm).offset().top,
elementHeight = $(elm).height();
if (eval == "object visible") return ((y < (viewportHeight + scrolltop)) && (y > (scrolltop - elementHeight)));
if (eval == "above") return ((y < (viewportHeight + scrolltop)));
}
1개 사용중인데 4개로 늘리려고 합니다.
코드를 좀 짧게 짤 수 있을까요?