亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

獲取x,y,坐標有問題,最后發現是自己太馬虎。。?;ㄙM好長時間解決

$(document).ready(function(){
??var?sub=$("#sub");
??var?activeRow;
??var?activeMenu;
??var?timer;
??var?mouseInsub=false;
??sub.on("mouseenter",function(e){//判斷鼠標是否在二級菜單中
???mouseInsub=true;
??})
??.on("mouseleave",function(e){
???mouseInsub=false;
??})
??var?mouseTrack?=?[];//定義一個裝鼠標移動位置的數組
??var?moveHandler?=?function(e){//獲取鼠標移動點的位置
???mouseTrack.push({
????x:e.pageX,
????y:e.pageY
???})
???if(mouseTrack.length>3){//只保存最新的三個鼠標位置點
????mouseTrack.shift();//刪除數組中的第一個元素,并返回第一元素的值
???}
??}
??$("#test")
??.on("mouseenter",function(e){
???sub.removeClass('none');
???$(document).bind("mousemove",moveHandler);//目的是為了獲取鼠標在一級菜單中上一次的位置和當前的位置,通過判斷當前位置滿不滿足在三角形內來判斷是否延遲
??})
??.on("mouseleave",function(e){
???sub.addClass('none');
???if(activeRow){
????activeRow.removeClass("active");
????activeRow=null;
???}
???if(activeMenu){
????activeMenu.addClass("none");
????activeMenu=null;
???}
???$(document).unbind("mousemove",moveHandler);

??})
??.on("mouseenter","li",function(e){
???if(!activeRow){//如果鼠標不在一級菜單內
????activeRow=$(e.target);
????activeRow.addClass("active");
????activeMenu=$("#"+activeRow.data("id"));
????activeMenu.removeClass("none");
????return?f;
???}
???if(timer){
????clearTimeout(timer);//不能理解debunce
???}
???var?currMousePos?=?mouseTrack[mouseTrack.length-1];
???var?leftCorner?=?mouseTrack[mouseTrack.length-2];
???var?delay?=?needDelay(sub,leftCorner,currMousePos);
???if(delay){
??timer=setTimeout(function(){
???if(mouseInsub){//300毫秒之后,如果鼠標在二級菜單里面,就不執行
????return?false;
???}
???//去掉上一個li的active&把對應的二級菜單隱藏
???????activeRow.removeClass("active");
????activeMenu.addClass("none");
???//為當前li的添加active&把對應的二級菜單顯示
????activeRow=$(e.target);
????activeRow.addClass("active");
????activeMenu=$("#"+activeRow.data("id"));
????activeMenu.removeClass("none");
????timer=null;
???},300);
????
}
else{
?var?preActiveRow=activeRow;
?var?preActiveMenu=activeMenu;
?
?activeRow=$(e.target);
?activeRow.addClass("active");
?preActiveRow.removeClass("active");
?preActiveMenu.addClass("none");
?activeMenu=$("#"+activeRow.data('id'));
?activeMenu.removeClass("none");
}
???
??})
})
//第二部分
function?sameSign(a,b){
?return(a^b)>=0;
}
//向量定義
function?vector(a,b){
?return{
??x:?b.x-a.x,
??y:?b.y-a.y
?}
}
//向量的叉乘運算
function?vectorProduct(v1,v2){
?return?v1.x?*?v2.y?-?v2.x?*?v1.y;
}
//叉乘判斷
function?isPointInTrangle(p,a,b,c){//p是當前鼠標位置,a是鼠標的上一個位置
?var?pa=vector(p,a);
?var?pb=vector(p,b);
?var?pc=vector(p,c);
?var?t1?=?vectorProduct(pa,pb);
?var?t2?=?vectorProduct(pb,pc);
?var?t3?=?vectorProduct(pc,pa);
?return?sameSign(t1,t2)&&sameSign(t2,t3);
}
function?needDelay(elem,leftCorner,currMousePos){
?var?offset?=?elem.offset();//offset獲取二級邊框的上下邊緣
?var?topLeft?=?{
??x:offset.left,
??y:offset.top
?}
?var?bottomLeft={
??x:offset.left,
??y:offset.top+elem.height()
?}
?return?isPointInTrangle(currMousePos,leftCorner,topLeft,bottomLeft);
}
//推薦一個有關叉乘的鏈接???
希望能幫助到大家(一定要自己敲呦)


正在回答

2 回答

樓主的正解,很多錯誤其實都是因為拼寫錯誤了導致的。。。。不過有個問題,就是在第48行代碼中 return f; 是什么鬼???

0 回復 有任何疑惑可以回復我~
#1

q_Amily 提問者

哈哈,太馬虎了,原來是return false的,刪除沒刪干凈
2017-06-05 回復 有任何疑惑可以回復我~

鏈接咋不見了??? http://www.cnblogs.com/TenosDoIt/p/4024413.html

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

獲取x,y,坐標有問題,最后發現是自己太馬虎。。?;ㄙM好長時間解決

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號