项目还是用angularJs + ionic1.0做的。为什么要自定义滚动条呢?
原因:IOS 自带的触摸事件导致页面上线滑动有空白。所以禁掉了默认的滑动事件:
if(ionic.Platfrom.isIOS()){
document.querySelector('body').addEventListener('touchmove',function(event){
event.preventDefault();
});

if ($scope.timeout) {
$timeout.cancel($scope.timeout);
}
if (!ionic.Platform.isIOS()) {
$scope.timeout = $timeout(function () {
try {
var select_ul = document.querySelector('#select_ul');
var select_bar = document.querySelector('#select_bar');
var select_ulH = select_ul.offsetHeight || 200;
var selectItemH = select_ul.firstElementChild.offsetHeight || 40;
var contentH = (select_ul.children.length) * selectItemH;
var offsetY;
if (select_ul && select_bar) {
if (select_ulH < contentH) {
//offsetY = select_ul.offsetHeight - (contentH - select_ul.offsetHeight) * 0.75;
offsetY = contentH * 0.46;
select_bar.style.height = offsetY + 'px';
select_bar.style.opacity = 1;
} else {
select_bar.style.height = 0;
select_bar.style.opacity = 0;
}
var fixOffsetY = select_ulH - offsetY;
var ratio = select_ulH / contentH;
select_ul.onscroll = function (e) {
console.log('select_ul.onscroll = function (e)');
var scrollOffset = e.target.scrollTop * ratio;
if (fixOffsetY < scrollOffset) {
scrollOffset = fixOffsetY - 2;
}
select_bar.style.transform = 'translate(' + 0 + 'px,' + scrollOffset + 'px)';
};
/* select_ul.addEventListener("touchstart", function (e) {
console.log('select_ul.addEventListener("touchstart", function (e)');
select_bar.style.height = offsetY + 'px';
select_bar.style.opacity = 1;
});*/
/*select_ul.addEventListener('touchend', function (e) {
$timeout(function () {
select_bar.style.height = 0;
select_bar.style.opacity = 0;
}, 500);
console.log('select_ul.addEventListener("touchend", function (e)');
});*/
}
} catch (e) {
console.log('angular.element(body) catch ' + e.toString());
}
}, 200);
} else {
$scope.timeout = $timeout(function () {
try {
var select_scroll = document.querySelector("#select_scroll");
var array_a = select_scroll.querySelectorAll("a");
var select_scroll_H = select_scroll.offsetHeight || 200;
var contentH = 0;
angular.forEach(array_a, function (item, index, array) {
contentH += item.offsetHeight || 40;
});
if (select_scroll.lastElementChild.lastElementChild) {
if (select_scroll_H < contentH) {
select_scroll.lastElementChild.lastElementChild.style.opacity = 1;
select_scroll.lastElementChild.lastElementChild.style.height = contentH * 0.5 + 'px';
} else {
select_scroll.lastElementChild.lastElementChild.style.opacity = 0;
select_scroll.lastElementChild.lastElementChild.style.height = 0;
}
}
} catch (e) {
}
}, 200);
}