Jithin Raj  P R
Jithin Raj P R

Reputation: 6797

On scroll increment value by '0.1'

What I want is to increment a value on the trigger by scroll by 0.1 using jQuery.

pval = 0
$(window).on('scroll', function() {
   pval++
   pval = 0.+pval
   console.log(pval);
});

I know it's a wrong way but I tried many ways but it's not happening anyway.Can you guys help me with this?

Upvotes: 0

Views: 666

Answers (1)

Suresh Atta
Suresh Atta

Reputation: 122008

Correct syntax is pval = 0.1 +pval or you can shorten with +=

var pval = 0;
$(window).on('scroll', function() {
   pval += 0.1; //short for pval =  pval+ 0.1
   console.log(pval);
});

Upvotes: 2

Related Questions