我根本沒有JS經驗。我搜索了一個編碼這個菜單的方法,我實際上設法使用一個小CSS。但是,當用戶單擊關閉按鈕時,菜單纔會關閉。如果用戶點擊菜單中的鏈接或頁面中的任何其他位置,菜單將保持打開狀態。我想出了這個代碼是這一個:JS用來隱藏菜單,當用戶點擊一個鏈接或頁面中的任何其他地方
<script>
var theMenu;
var originTop;
window.onload = function() {
//Click to open the submenu
element = document.getElementById("buttonu101541");
element.onclick = openMenu;
//Top position
originTop = document.getElementById("buttonu100976").style.top;
//Get the Menu element
theMenu = document.getElementById("buttonu100976");
//Close button
closeBtn = document.getElementById("buttonu101584");
closeBtn.onclick = closeMenu;
}
function openMenu(){
theMenu.style.top = 0;
}
function closeMenu(){
theMenu.style.top = originTop;
}
</script>
<style>
#buttonu100976{
transition-property: top;
transition-duration: 1s;
transition-timing-function: ease;
-webkit-transition-property: top;
-webkit-transition-duration: 1s;
-webkit-transition-timing-function: ease;
}
#buttonu101541{
cursor: pointer;
cursor: hand;
}
#buttonu101584{
cursor: pointer;
cursor: hand;
}
</style>
老實說,我不知道如何通過這一點。我感謝任何幫助。謝謝。
可以請你創建一個演示/你可以使用的jsfiddle或plunker – brk
這可能會幫助他人提供,如果你的答案說什麼「繼續前進」。即你期望得到什麼結果?我假設你期望菜單在點擊鏈接時消失。這是一個正確的假設嗎? – MikeT
嗨。謝謝你的回覆,我很抱歉拖延。我是新來的這種論壇。我甚至不知道你們回答。以爲我會收到通知郵件。 :( user2181397你是什麼意思?如果你想看看我想要做什麼,請查看www.adielrios.com,將鼠標懸停在右上角的菜單圖標上,將鼠標懸停在「saúdemental 「然後點擊」outros transtornos「。這就是JS觸發器。 MikeT,你的假設是精確的:這正是我想要的!:) –