365体育网址-365手机app下载-沙巴体育投注官网-文昌中学
海南省365体育网址-365手机app下载-沙巴体育投注官网欢迎您!
>
> var oneInner = document.querySelector(".floatKuang"); var oneInnertwo = document.querySelector(".floatKuangK"); var stepX = 10; var stepY = 10; var stepXX = 10; var stepYY = 10; function moves() { var tops = oneInner.offsetTop; var lefts = oneInner.offsetLeft; if (lefts >= getViewPort().width - oneInner.offsetWidth || lefts <= 0) { stepX = -stepX }; if (tops >= getViewPort().height - oneInner.offsetHeight || tops <= 0) { stepY = -stepY; } tops += stepY; lefts += stepX; oneInner.style.top = tops + "px"; oneInner.style.left = lefts + "px"; } function movesTwo() { var tops = oneInnertwo.offsetTop var lefts = oneInnertwo.offsetLeft // console.log(tops); if (lefts >= getViewPort().width - oneInnertwo.offsetWidth || lefts <= Math.abs(stepXX)) { stepXX = -stepXX } if (tops >= getViewPort().height - oneInnertwo.offsetHeight || tops <= Math.abs(stepXX)) { stepYY = -stepYY } tops += stepYY; lefts += stepXX; // console.log(lefts); oneInnertwo.style.top = tops + "px" oneInnertwo.style.left = lefts + "px" } //定时器 var a1a = setInterval(moves, 100); var a2a = setInterval(movesTwo, 100); //悬停停止 oneInner.onmouseover = function () { clearInterval(a1a); oneInner.style.width= 600+'px'; } //悬停停止 oneInnertwo.onmouseover = function () { clearInterval(a2a); oneInnertwo.style.width= 600+'px'; } //放手继续运动 oneInner.onmouseout = function () { // alert(123); a1a = setInterval(moves, 100); oneInner.style.width= 300 + "px"; } //放手继续运动 oneInnertwo.onmouseout = function () { a2a = setInterval(movesTwo, 100); oneInnertwo.style.width= 300+ "px"; } function getViewPort() { if (document.compatMode == "BackCompat") { //浏览器嗅探,混杂模式 return { width: document.body.clientWidth, height: document.body.clientHeight }; } else { return { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight }; } } >