您可以使用鼠标滚轮事件来查看在您的 popstate 事件之前是否已在触控板上执行了水平滚动:
// boolean that stores if a swipe has been performed.
var bScrolled = false;
// countdown in ms before resetting the boolean.
var iTime = 1000;
var oTimeout;
window.addEventListener('mousewheel', function(e) {
if (e.wheelDeltaY === 0) {
// there is an horizontal scroll
if (!bScrolled) {
// no need to set bScrolled to true if it has been done within the iTime time.
bScrolled = true;
oTimeout = setTimeout(function(){
bScrolled = false;
}, iTime);
}
}
});
window.onpopstate = function() {
// clear the timeout to be sure we keep the correct value for bScrolled
clearTimeout(oTimeout);
// check if there has been a swipe prior to the change of history state
if (bScrolled) {
// check which browser & OS the user is using, then
// trigger your awesome custom transition.
}
}