Pages

顯示具有 Javascript 標籤的文章。 顯示所有文章
顯示具有 Javascript 標籤的文章。 顯示所有文章

2012年7月3日 星期二

How can UP/DOWN scroll be distinguished??

he easiest way for me to tell was...
var tempScrollTop, currentScrollTop = 0;
$("#div").scroll(function(){
currentScrollTop = $("#div").scrollTop();
if (tempScrollTop < currentScrollTop )
//scrolling down
else if (tempScrollTop > currentScrollTop )
//scrolling up
tempScrollTop = currentScrollTop;
}
This works with mousewheel, up/down arrows, and slidebar

2010年9月16日 星期四

讓數字有逗點分隔

function addCommas(nStr)
{
 nStr += '';
 x = nStr.split('.');
 x1 = x[0];
 x2 = x.length > 1 ? '.' + x[1] : '';
 var rgx = /(\d+)(\d{3})/;
 while (rgx.test(x1)) {
  x1 = x1.replace(rgx, '$1' + ',' + '$2');
 }
 return x1 + x2;
}