var overscroll = function (els) { for (var i = 0; i < els.length; ++i) { var el = els[i]; el.addEventListener('touchstart', function () { var top = this.scrollTop, totalScroll = this.scrollHeight, currentScroll = top + this.offsetHeight; if (top === 0) { this.scrollTop = 1; } else if (currentScroll === totalScroll) { this.scrollTop = top - 1; } }); el.addEventListener('touchmove', function (evt) { if (this.offsetHeight < this.scrollHeight) evt._isScroller = true; }); } }; //禁止body的滚动事件 document.body.addEventListener('touchmove', function (evt) { if (!evt._isScroller) { evt.preventDefault(); } }); //给class为.scroll的元素加上自定义的滚动事件 overscroll(document.querySelectorAll('.scroll')); $(function () { var $container = window.innerHeight; var $globalHeader = $(".global-header").height(); var $containerHeight = $container - $globalHeader; $(".viewport .container").height($containerHeight); //弹出动画 $('#iphoneCnt1').animate({ 'margin-top': -1.2 + "rem" }, 2000); $('#iphoneCnt2').animate({ 'margin-top': -0.69 + "rem" }, 1500); $('#iphoneCnt3').animate({ 'margin-top': -0.09 + "rem" }, 1000); //弹出动画 end });