Native JS realizes the mouse follow-up effect

Don’t say, please see the code:

  mouse follow-up effect   * {margin: 0; Padding: 0;} img {position: absolute; top: 0; Left: 0;}       (Function (Window) {// Get Object VAR IMG = Document.GtelementByid ("IMG"); // Add Click event to the page, mouse click, slide to the mouse, position document.onclick = function (Event) {var evenet = event || window.event; // Get the mouse coordinates on the page var pageX = event.pageX || event.clientX + document.documentElement.scrollLeft; var pageY = event.pageY || event.clientY + document.documentElement.scrollTop; / / Minus the picture of the picture itself is half, so that the mouse is in the middle Pagex - img.offsetwidth / 2; pagey = pagey - img.offsetwidth / 2; animate (img, {"left": Pagex, "TOP": Pagey});}; // Package slower function Function Animate (obj, json, fn) {clearinterval (obj.timer); obj.timer = setInterval (FunCtion () {var flog = true; for (k === "zindex") {obj.style [k] = json [k];} else if (k === "Opacity" ) {var Leader = getStyle (OBJ, K) * 100; var target = json [k] * 100; var step = (target - leader) / 10; step = step> 0? Math.ceil (Step): Math. FLOOR (Step); Leader = Leader + Step; Obj.Style [K] = Leader / 100;} else {var Leader = PARSEINT (GetStyle (Obj, K)); var target = json [k]; var step = Target - Leader) / 10; Step = Step> 0? Math.ceil (STEP): Math.Floor (Step); Leader = Leader + Step; Obj.Style [K] = Leader + "PX";}; IF Leader! == Target) {flog = false;}}} {clearinterval (obj.timer); if (fn) {fn ();};};}, 15)}; // After the package acquisition calculation Style function function getStyle (Obj, Attr){if (window.getComputedStyle) {return window.getComputedStyle (obj, null) [attr];} else {return obj.currentStyle [attr];};};} (window)   Native JS realizes the mouse follow-up effect插图    The above is all of this article, I hope this paper will bring certain help to everyone's learning or work, and I hope to support Tumi cloud!                      
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment