2017-04-10 57 views
-2

我有兩個問題,因爲我很新。有沒有更簡單的方法來簡化這段代碼?也可以有人解釋逗號?

1)有沒有簡化此代碼的方法? 基本上懸停的元素出現一個div。當您使用鼠標進行操作時,我想在網站http://indicius.com/的社交圖標上覆制效果。這是創建這種效果的正確方法嗎?

2)有人可以向我解釋這裏的逗號函數嗎?我的意思是在一個事件中,我看到兩個函數(實際上是在做我正在尋找的工作),但我想了解逗號是什麼意思? 我想了解第二個「職位」在逗號事件之後意味着什麼。

希望很明確。

$(".social-size-logo").hover(
    function() { 
    $(".color-social-div").css({ 
     "opacity": "1", 
     "z-index": "999" 
    }); 
    }, 
    function() { 
    $(".color-social-div").css({ 
     "opacity": "0", 
     "z-index": "-1" 
    }); 
    }); 
+0

請參閱[hover()](https://api.jquery.com/hover/)的文檔。 – showdev

+2

'.hover(handlerIn,handlerOut)' – James

+2

您應該改用CSS':hover'選擇器。 – SLaks

回答

0

jQuery的懸停函數接受兩種方法作爲參數,第一個上鼠標執行輸入的所選擇的元件,第二個時鼠標闊葉的元素。

$(element).hover(mouseInHandler, mouseOutHandler); 

你可以閱讀更多關於它現在here

,來到您發佈的片段,我會嘗試內嵌解釋它

$(".social-size-logo").hover(// Attach the hover event handler 
    function() { // This is the `mouseIn` method 
    $(".color-social-div").css({ //We add the CSS to make the element visible, 
     "opacity": "1", // set the opacity to 1 to make it visible 
     "z-index": "999" // bump up the z-index to bring it to the top 
    }); 
    }, 
    function() {// This is the `mouseOut` method 
    $(".color-social-div").css({ 
     "opacity": "0", 
     "z-index": "-1" 
    }); 
    }); 

有很多花哨的動畫和過渡到一起,使該動畫,但這一切歸結爲:

  1. 用戶輸入社會圖標區域 - >火起來,帶來聚焦在頁面包裝,也其放在一切
  2. 顯示的圖標相應的覆蓋 暗示頂部的事件:檢查div.overlays-wrapper元素的懸停行爲理解這
  3. 當用戶離開 - >重置所有內容
相關問題