Showing
2 changed files
with
99 additions
and
1 deletions
@@ -1707,6 +1707,103 @@ var start = 0, | @@ -1707,6 +1707,103 @@ var start = 0, | ||
1707 | 1707 | ||
1708 | lazyLoad($('img.lazy')); | 1708 | lazyLoad($('img.lazy')); |
1709 | 1709 | ||
1710 | +function preventDefault(e) { | ||
1711 | + e = e || window.event; | ||
1712 | + e.preventDefault && e.preventDefault(); | ||
1713 | + e.returnValue = false; | ||
1714 | +} | ||
1715 | + | ||
1716 | +function stopPropagation(e){ | ||
1717 | + e = e || window.event; | ||
1718 | + e.stopPropagation && e.stopPropagation(); | ||
1719 | + e.cancelBubble = false; | ||
1720 | +} | ||
1721 | + | ||
1722 | +function innerScroll(e){ | ||
1723 | + // 阻止冒泡到document | ||
1724 | + // document上已经preventDefault | ||
1725 | + stopPropagation(e); | ||
1726 | + | ||
1727 | + var delta = e.wheelDelta || e.detail || 0; | ||
1728 | + var box = $(this).get(0); | ||
1729 | + | ||
1730 | + if($(box).height() + box.scrollTop >= box.scrollHeight){ | ||
1731 | + if(delta < 0) { | ||
1732 | + preventDefault(e); | ||
1733 | + return false; | ||
1734 | + } | ||
1735 | + } | ||
1736 | + if(box.scrollTop === 0){ | ||
1737 | + if(delta > 0) { | ||
1738 | + preventDefault(e); | ||
1739 | + return false; | ||
1740 | + } | ||
1741 | + } | ||
1742 | + // 会阻止原生滚动 | ||
1743 | + // return false; | ||
1744 | +} | ||
1745 | + | ||
1746 | +var disableScroll = function(){ | ||
1747 | + $(document).on('mousewheel', preventDefault); | ||
1748 | + $(document).on('touchmove', preventDefault); | ||
1749 | +}; | ||
1750 | + | ||
1751 | +var enableScroll = function(){ | ||
1752 | + $(document).off('mousewheel', preventDefault); | ||
1753 | + $(document).off('touchmove', preventDefault); | ||
1754 | +}; | ||
1755 | + | ||
1756 | +// bind | ||
1757 | +/**$('#closePopup').on('click', function(e){ | ||
1758 | + $('#popupLayer').hide(); | ||
1759 | + $('#bgMask').hide(); | ||
1760 | + enableScroll(); | ||
1761 | +});**/ | ||
1762 | + | ||
1763 | +// 内部可滚 | ||
1764 | +$sideNav.on('mousewheel', innerScroll); | ||
1765 | +// 外部禁用 | ||
1766 | +disableScroll(); | ||
1767 | + | ||
1768 | + | ||
1769 | +// 移动端touch重写 | ||
1770 | +var startX, startY; | ||
1771 | +$sideNav.on('touchstart', function(e){ | ||
1772 | + startX = e.changedTouches[0].pageX; | ||
1773 | + startY = e.changedTouches[0].pageY; | ||
1774 | +}); | ||
1775 | + | ||
1776 | +// 仿innerScroll方法 | ||
1777 | +$sideNav.on('touchmove', function(e){ | ||
1778 | + e.stopPropagation(); | ||
1779 | + | ||
1780 | + var deltaX = e.changedTouches[0].pageX - startX; | ||
1781 | + var deltaY = e.changedTouches[0].pageY - startY; | ||
1782 | + | ||
1783 | + // 只能纵向滚 | ||
1784 | + if(Math.abs(deltaY) < Math.abs(deltaX)){ | ||
1785 | + e.preventDefault(); | ||
1786 | + return false; | ||
1787 | + } | ||
1788 | + | ||
1789 | + var box = $(this).get(0); | ||
1790 | + | ||
1791 | + if($(box).height() + box.scrollTop >= box.scrollHeight){ | ||
1792 | + if(deltaY < 0) { | ||
1793 | + e.preventDefault(); | ||
1794 | + return false; | ||
1795 | + } | ||
1796 | + } | ||
1797 | + if(box.scrollTop === 0){ | ||
1798 | + if(deltaY > 0) { | ||
1799 | + e.preventDefault(); | ||
1800 | + return false; | ||
1801 | + } | ||
1802 | + } | ||
1803 | + // 会阻止原生滚动 | ||
1804 | + // return false; | ||
1805 | +}); | ||
1806 | + | ||
1710 | $('.nav-btn').on('touchstart', function(event) { | 1807 | $('.nav-btn').on('touchstart', function(event) { |
1711 | $sideNav.css('pointer-events', 'none'); | 1808 | $sideNav.css('pointer-events', 'none'); |
1712 | $mobileWrap.addClass('menu-open'); | 1809 | $mobileWrap.addClass('menu-open'); |
@@ -1740,6 +1837,7 @@ function hideSideBar() { | @@ -1740,6 +1837,7 @@ function hideSideBar() { | ||
1740 | height: 'auto', | 1837 | height: 'auto', |
1741 | overflow: 'auto' | 1838 | overflow: 'auto' |
1742 | }); | 1839 | }); |
1840 | + enableScroll(); | ||
1743 | } | 1841 | } |
1744 | } | 1842 | } |
1745 | 1843 | ||
@@ -1749,7 +1847,7 @@ $('.overlay').on('touchstart', function(e) { | @@ -1749,7 +1847,7 @@ $('.overlay').on('touchstart', function(e) { | ||
1749 | }); | 1847 | }); |
1750 | 1848 | ||
1751 | //点击一级导航,弹出二级导航 | 1849 | //点击一级导航,弹出二级导航 |
1752 | -$sideNav.on('touchstart', 'li', function(e) { | 1850 | +$sideNav.on('touchend', 'li', function(e) { |
1753 | if ($(this).find('.sub-nav').size() > 0) { | 1851 | if ($(this).find('.sub-nav').size() > 0) { |
1754 | $('.sub-nav').removeClass('show'); | 1852 | $('.sub-nav').removeClass('show'); |
1755 | $(this).find('.sub-nav').addClass('show'); | 1853 | $(this).find('.sub-nav').addClass('show'); |
This diff could not be displayed because it is too large.
-
Please register or login to post a comment