最終效果
這里的關(guān)鍵主要是判斷鼠標(biāo)是從哪個(gè)方向進(jìn)入和離開(kāi)的
$("li").on("mouseenter mouseleave",function(e) { var w = this.offsetWidth; var h = this.offsetHeight; var x = e.pageX - this.getBoundingClientRect().left - w/2; var y = e.pageY - this.getBoundingClientRect().top - h/2; var direction = Math.round((((Math.atan2(y, x) * 180 / Math.PI) + 180) / 90) + 3) % 4; //direction的值為“0,1,2,3”分別對(duì)應(yīng)著“上,右,下,左” var eventType = e.type; var res = Math.atan2(y, x) / (Math.PI / 180) + 180 ; $('.line').css('transform','rotate('+ res +'deg)'); // console.log(((Math.atan2(y, x) * 180 / Math.PI) + 180)); &n