Js determines the direction of mouse movement, js determines the mouse
Js Code:
Var gaga = function (wrap) {var wrap = document. getElementById (wrap); var hoverDir = function (e) {var w = wrap. offsetWidth, h = wrap. offsetHeight, x = (e. clientX-wrap. offsetLeft-(w/2) * (w> h? (H/w): 1), y = (e. clientY-wrap. offsetTop-(h/2) * (h> w? (W/h): 1), // top (0) Right (1) Bottom (2) Left (3) direction = Math. round (Math. atan2 (y, x) * (180/Math. PI) + 180)/90) + 3) % 4, eventType = e. type, dirName = new Array ('core', 'right', 'under', 'left'); if (e. type = 'mouseover' | e. type = 'mouseenter') {wrap. innerHTML = dirName [ction] + '';} else {wrap. innerHTML = dirName [ction] + 'off';} if (window. addEventListener) {wrap. addEventListener ('mouseover', hoverDir, false); wrap. addEventListener ('mouseout', hoverDir, false);} else if (window. attachEvent) {wrap. attachEvent ('onmouseenter', hoverDir); wrap. attachEvent ('onmouseleave ', hoverDir); }}// gaga ('agagagaga1'); gaga ('agagagaga2 ');
The effect is as follows:
This method is compatible with all mainstream browsers, including IE6