// 滚动到指定位置---begin function getscrolltop() { return (document.scrollingelement && document.scrollingelement.scrolltop) || document.documentelement.scrolltop || document.body.scrolltop; } function setscrolltop(st) { if (!st) st = 0; document.documentelement.scrolltop = document.body.scrolltop = st; } function scrolltop(scrolltop, time) { scrolltop = scrolltop ? scrolltop : 0; time = time ? time : 500; const cubic = function (value) { return math.pow(value, 3) }; const easeinoutcubic = function (value) { return value < 0.5 ? cubic(value * 2) / 2 : 1 - cubic((1 - value) * 2) / 2 } const begintime = date.now(); const beginvalue = getscrolltop(); const raf = window.requestanimationframe || (function (func) { return settimeout(func, 16) }); const framefunc = function () { if (isnan(+time) || +time === 0) { setscrolltop(scrolltop); return; } const progress = (date.now() - begintime) / time; if (progress < 1) { setscrolltop( scrolltop + (beginvalue - scrolltop) * (1 - easeinoutcubic(progress)) ); raf(framefunc); } else { setscrolltop(scrolltop); } }; raf(framefunc); }; /** 获取指定元素距离页面顶部距离 */ function getelementtopagetop(el) { if(el.parentelement) { return getelementtopagetop(el.parentelement) + el.offsettop } return el.offsettop } /** 获取指定元素高度 */ function getelementheight(el) { return el.clientheight; } function playfirstvideo() { var videocontain = $($('.index-top-banner .swiper-slide')[0]); var curvideo = videocontain.find('video'); if (curvideo.length) { curvideo.trigger('play'); } }