Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
fix(mac scroll x reverse fix): mac scroll x reverse fix and scroll op…
Browse files Browse the repository at this point in the history
…timization
  • Loading branch information
tubiaoge committed Jul 30, 2020
1 parent 35820b3 commit 8eb68e8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export default function luckysheetHandler() {
if(browser.mobilecheck()){
mobileinit();
}


const os = browser.detectOS(), isMac = os=="Mac"?true:false, scrollNum = isMac?1:3;

//滚动监听
$("#luckysheet-cell-main").scroll(function () {

Expand Down Expand Up @@ -100,41 +102,18 @@ export default function luckysheetHandler() {
let rowscroll = 0;

//一次滚动三行或三列
if(event.deltaX != 0){
let col_ed;

if(event.deltaX < 0){
col_ed = col_st + 3;

if(col_ed >= visibledatacolumn_c.length){
col_ed = visibledatacolumn_c.length - 1;
}
}
else{
col_ed = col_st - 3;

if(col_ed < 0){
col_ed = 0;
}
}

colscroll = col_ed == 0 ? 0 : visibledatacolumn_c[col_ed - 1];

$("#luckysheet-scrollbar-x").scrollLeft(colscroll);
}

if(event.deltaY != 0){
let row_ed;

if(event.deltaY < 0){
row_ed = row_st + 3;
row_ed = row_st + scrollNum;

if(row_ed >= visibledatarow_c.length){
row_ed = visibledatarow_c.length - 1;
}
}
else{
row_ed = row_st - 3;
row_ed = row_st - scrollNum;

if(row_ed < 0){
row_ed = 0;
Expand All @@ -145,6 +124,28 @@ export default function luckysheetHandler() {

$("#luckysheet-scrollbar-y").scrollTop(rowscroll);
}
else if(event.deltaX != 0){
let col_ed;

if((isMac && event.deltaX >0 ) || (!isMac && event.deltaX < 0)){
col_ed = col_st + scrollNum;

if(col_ed >= visibledatacolumn_c.length){
col_ed = visibledatacolumn_c.length - 1;
}
}
else{
col_ed = col_st - scrollNum;

if(col_ed < 0){
col_ed = 0;
}
}

colscroll = col_ed == 0 ? 0 : visibledatacolumn_c[col_ed - 1];

$("#luckysheet-scrollbar-x").scrollLeft(colscroll);
}
});

$("#luckysheet-scrollbar-x").scroll(function(){
Expand Down
23 changes: 23 additions & 0 deletions src/global/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,29 @@ const browser = {
}

return _this.luckysheetrefreshfixednum;
},
detectOS() {
var userAgent = navigator.userAgent;
var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
if (isMac) return "Mac";
var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
if (isUnix) return "Unix";
var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
if (isLinux) return "Linux";
if (isWin) {
var isWin2K = userAgent.indexOf("Windows NT 5.0") > -1 || userAgent.indexOf("Windows 2000") > -1;
if (isWin2K) return "Win2000";
var isWinXP = userAgent.indexOf("Windows NT 5.1") > -1 || userAgent.indexOf("Windows XP") > -1;
if (isWinXP) return "WinXP";
var isWin2003 = userAgent.indexOf("Windows NT 5.2") > -1 || userAgent.indexOf("Windows 2003") > -1;
if (isWin2003) return "Win2003";
var isWinVista= userAgent.indexOf("Windows NT 6.0") > -1 || userAgent.indexOf("Windows Vista") > -1;
if (isWinVista) return "WinVista";
var isWin7 = userAgent.indexOf("Windows NT 6.1") > -1 || userAgent.indexOf("Windows 7") > -1;
if (isWin7) return "Win7";
}
return "other";
}
};

Expand Down

0 comments on commit 8eb68e8

Please sign in to comment.