Witam, chcę by funkcje które zostały napisane wykonywały się gdy wysokość okna przeglądarki była większa od 920 lub gdy mniejsza to podczas przewinięcia scrolla o 100 pikseli. Pierwszy warunek u mnie działa, drugi już nie. Będę wdzięczny jesli ktoś też zmniejszy ilość kodu do prostej postaci

$(document).ready(function(){
$('#c1').text(0);
$('#c2').text(0);
$('#c3').text(0);
$('#c4').text(0);
var scrolledmax = (window.innerHeight||document.body.clientHeight);
var scrolled = $(window).scrollTop();
if (scrolledmax > 920)
{
jQuery({someValue: 0}).animate({someValue: 20}, {
duration: 2000,
easing:'swing',
step: function() {
$('#c1').text(Math.ceil(this.someValue));
}
});
jQuery({someValue: 0}).animate({someValue: 100}, {
duration: 2000,
easing:'swing',
step: function() {
$('#c2').text(Math.ceil(this.someValue));
}
});
jQuery({someValue: 0}).animate({someValue: 1000}, {
duration: 2000,
easing:'swing',
step: function() {
$('#c3').text(Math.ceil(this.someValue));
}
});
jQuery({someValue: 0}).animate({someValue: 2000}, {
duration: 2000,
easing:'swing',
step: function() {
$('#c4').text(Math.ceil(this.someValue));
}
});
}
var scroll1 = 0;
if (scroll1<scrolled)
var scroll1 = scrolled;
if (scrolledmax <= 920 && scroll1>100)
{
jQuery({someValue: 0}).animate({someValue: 20}, {
duration: 2000,
easing:'swing',
step: function() {
$('#c1').text(Math.ceil(this.someValue));
}
});
jQuery({someValue: 0}).animate({someValue: 100}, {
duration: 2000,
easing:'swing',
step: function() {
$('#c2').text(Math.ceil(this.someValue));
}
});
jQuery({someValue: 0}).animate({someValue: 1000}, {
duration: 2000,
easing:'swing',
step: function() {
$('#c3').text(Math.ceil(this.someValue));
}
});
jQuery({someValue: 0}).animate({someValue: 2000}, {
duration: 2000,
easing:'swing',
step: function() {
$('#c4').text(Math.ceil(this.someValue));
}
});
}
});