2017-10-03 7 views
1

그래서 약간의 메뉴 아이디어에 대한 테스트를하고있었습니다. 아이디어는 단지 화면의 왼쪽 상단 모서리에 작은 점이있는 것입니다. 덮어 씌우면 상자 그림자가 커지므로 클릭하면 확대됩니다 (너비 : 100 %, 높이 : 100 %). 그러면 같은 색상의 숨겨진 div가 표시됩니다. 그러면 메뉴가 닫히고 닫기 버튼 (CHIUDI)을 클릭하면 메뉴가 열립니다. 그러나 화면 모서리에있는 점의 호버 속성은 더 이상 작동하지 않습니다.
CSS 규칙을 수정하기 위해 JavaScript를 사용하고 있기 때문에이 문제가 발생한다고 생각합니다. 메뉴를 닫기 위해 메뉴를 닫을 때는 0을 box-shadow로 설정합니다.
아마도 이것이 문제 일 것입니다. : hover CSS 속성.
순수한 JavaScript를 사용하여 문제를 해결할 수 있습니까? (jQuery 없음). !

다음은 코드입니다 :

JavaScript Dom 후에 CSS hover가 작동하지 않습니다.

<html> 
 

 
<head> 
 
    <title>Design Tests</title> 
 
    <style> 
 
    @import url('https://fonts.googleapis.com/css?family=Raleway:200'); 
 
    #button { 
 
     position: fixed; 
 
     width: 50px; 
 
     height: 50px; 
 
     background-color: blue; 
 
     border-radius: 25px; 
 
     transition-duration: 500ms; 
 
     z-index: 1; 
 
     cursor: pointer; 
 
    } 
 
    
 
    #button:hover { 
 
     box-shadow: 0px 0px 0px 30px rgba(0, 0, 255, 1); 
 
    } 
 
    
 
    #menu_container { 
 
     position: fixed; 
 
     width: 100%; 
 
     height: 100%; 
 
     top: 0; 
 
     right: 0; 
 
     left: 0; 
 
     bottom: 0; 
 
     background-color: rgba(0, 0, 255, 1); 
 
     z-index: 0; 
 
     visibility: hidden; 
 
    } 
 
    
 
    #menu { 
 
     transition-duration: 500ms; 
 
     opacity: 0; 
 
    } 
 
    
 
    #close_menu { 
 
     color: white; 
 
     font-family: raleway; 
 
     cursor: pointer; 
 
    } 
 
    </style> 
 
</head> 
 

 
<body> 
 
    <div id="button" onclick="openMenu()"></div> 
 
    <div id="menu_container"> 
 
    <div id="menu"> 
 
     <center> 
 
     <h1 id="close_menu" onclick="closeMenu()">CHIUDI</h1> 
 
     </center> 
 
    </div> 
 
    </div> 
 
    <script> 
 
    function openMenu() { 
 
     document.getElementById('button').style.boxShadow = '0px 0px 0px 100em rgba(0,0,255,1)'; 
 
     setTimeout(showMenu, 500); 
 
    } 
 

 
    function showMenu() { 
 
     document.getElementById('menu_container').style.visibility = 'visible'; 
 
     document.getElementById('menu_container').style.zIndex = '2'; 
 
     document.getElementById('menu').style.opacity = '1'; 
 
    } 
 

 
    function closeMenu() { 
 
     document.getElementById('menu').style.opacity = '0'; 
 
     setTimeout(hideMenu, 400); 
 
    } 
 

 
    function hideMenu() { 
 
     document.getElementById('menu_container').style.visibility = 'hidden'; 
 
     document.getElementById('menu_container').style.zIndex = '0'; 
 
     document.getElementById('button').style.boxShadow = '0px 0px 0px 0px rgba(0,0,255,1)'; 
 
    } 
 
    </script> 
 
</body> 
 

 
</html>

-UPDATE-

나는 CSS 중요한 속성을 사용하려고하지만 그것은 작동하지 않습니다. ! important 규칙을 사용하면 JavaScript가 해당 규칙에 영향을 미치지 않지만 (그렇다면) 규칙 자체에 상자 그림자를 사용해야하므로 JavaScript가 편집해야합니다.
기본적으로 박스 섀도우 호버 규칙에서! important를 사용하여이 버그를 수정 하겠지만 메뉴를 열면 애니메이션이 더 이상 표시되지 않습니다.

+0

죄송합니다 영어 문법 오류 : 여기 기능입니다. – Zero

답변

0

JS를 사용하여 스타일을 적용하면 인라인 스타일이되며 다음으로 우선 순위가 높아집니다. 당신은 중요한 추가 할 수 있습니다 : 마우스를 다음과 같이 :

<html> 
 

 
<head> 
 
    <title>Design Tests</title> 
 
    <style> 
 
    @import url('https://fonts.googleapis.com/css?family=Raleway:200'); 
 
    #button { 
 
     position: fixed; 
 
     width: 50px; 
 
     height: 50px; 
 
     background-color: blue; 
 
     border-radius: 25px; 
 
     transition-duration: 500ms; 
 
     z-index: 1; 
 
     cursor: pointer; 
 
    } 
 
    
 
    #button:hover { 
 
     box-shadow: 0px 0px 0px 30px rgba(0, 0, 255, 1)!important; 
 
    } 
 
    
 
    #menu_container { 
 
     position: fixed; 
 
     width: 100%; 
 
     height: 100%; 
 
     top: 0; 
 
     right: 0; 
 
     left: 0; 
 
     bottom: 0; 
 
     background-color: rgba(0, 0, 255, 1); 
 
     z-index: 0; 
 
     visibility: hidden; 
 
    } 
 
    
 
    #menu { 
 
     transition-duration: 500ms; 
 
     opacity: 0; 
 
    } 
 
    
 
    #close_menu { 
 
     color: white; 
 
     font-family: raleway; 
 
     cursor: pointer; 
 
    } 
 
    </style> 
 
</head> 
 

 
<body> 
 
    <div id="button" onclick="openMenu()"></div> 
 
    <div id="menu_container"> 
 
    <div id="menu"> 
 
     <center> 
 
     <h1 id="close_menu" onclick="closeMenu()">CHIUDI</h1> 
 
     </center> 
 
    </div> 
 
    </div> 
 
    <script> 
 
    function openMenu() { 
 
     document.getElementById('button').style.boxShadow = '0px 0px 0px 100em rgba(0,0,255,1)'; 
 
     setTimeout(showMenu, 500); 
 
    } 
 

 
    function showMenu() { 
 
     document.getElementById('menu_container').style.visibility = 'visible'; 
 
     document.getElementById('menu_container').style.zIndex = '2'; 
 
     document.getElementById('menu').style.opacity = '1'; 
 
    } 
 

 
    function closeMenu() { 
 
     document.getElementById('menu').style.opacity = '0'; 
 
     setTimeout(hideMenu, 400); 
 
    } 
 

 
    function hideMenu() { 
 
     document.getElementById('menu_container').style.visibility = 'hidden'; 
 
     document.getElementById('menu_container').style.zIndex = '0'; 
 
     document.getElementById('button').style.boxShadow = '0px 0px 0px 0px rgba(0,0,255,1)'; 
 
    } 
 
    </script> 
 
</body> 
 

 
</html>

하지만 더 나은 아이디어는 다음과 같이 JS 그들을 클래스를 사용하여 전환하는 것입니다

function openMenu() { 
 
    document.getElementById('button').className="open"; 
 
    setTimeout(showMenu, 500); 
 
} 
 

 
function showMenu() { 
 
document.getElementById('menu_container').className="show"; 
 
document.getElementById('menu').style.opacity = '1'; 
 
} 
 

 
function closeMenu() { 
 
    document.getElementById('menu').style.opacity = '0'; 
 
    setTimeout(hideMenu, 400); 
 
} 
 

 

 
function hideMenu() { 
 
document.getElementById('menu_container').className=""; 
 
    document.getElementById('button').className=""; 
 
}
@import url('https://fonts.googleapis.com/css?family=Raleway:200'); 
 
#button { 
 
    position: fixed; 
 
    width: 50px; 
 
    height: 50px; 
 
    background-color: blue; 
 
    border-radius: 25px; 
 
    transition-duration: 500ms; 
 
    z-index: 1; 
 
    cursor: pointer; 
 
} 
 
#button.open { 
 
box-shadow: 0px 0px 0px 100em rgba(0,0,255,1); 
 
} 
 

 
#button:hover { 
 
    box-shadow: 0px 0px 0px 30px rgba(0, 0, 255, 1); 
 
} 
 

 
#menu_container { 
 
    position: fixed; 
 
    width: 100%; 
 
    height: 100%; 
 
    top: 0; 
 
    right: 0; 
 
    left: 0; 
 
    bottom: 0; 
 
    background-color: rgba(0, 0, 255, 1); 
 
    z-index: 0; 
 
    visibility: hidden; 
 
    opacity:0; 
 
} 
 
#menu_container.show { 
 
visibility: visible; 
 
z-index:2; 
 
opacity:1; 
 
} 
 

 
#menu { 
 
    transition-duration: 500ms; 
 
    opacity: 0; 
 
} 
 

 
#close_menu { 
 
    color: white; 
 
    font-family: raleway; 
 
    cursor: pointer; 
 
}
<html> 
 

 
<body> 
 
    <div id="button" onclick="openMenu()"></div> 
 
    <div id="menu_container"> 
 
    <div id="menu"> 
 
     <center> 
 
     <h1 id="close_menu" onclick="closeMenu()">CHIUDI</h1> 
 
     </center> 
 
    </div> 
 
    </div> 
 
</body>

+0

나는 중요한 것을 추가하면 오픈 메뉴 애니메이션을 만들기 위해 JavaScript가 중요한 속성을 사용한다는 것이 문제를 해결할 것이지만 새로운 문제가 생길 수 있다는 점에서 문제가있다. 애니메이션을 다시 만들려면 어떻게해야합니까? div 차원을 변경하여 시도했지만 애니메이션이 이와 같이 잘 보이지 않습니다. 다른 아이디어가 있습니까? – Zero

+0

@Zero 대체 솔루션으로 내 대답을 업데이트했습니다.) –

+0

JavaScript DOM을 사용하여 호버 등록 정보를 만들 수 있습니까? 그것은 문제를 해결할 것입니다. – Zero

0

나는 이것을 만들었습니다. 자신의 도전 과제로 더 많은 것을했지만 javascript를 사용하여 마우스 오버 효과를 얻을 수있었습니다. CSS에서 :hover을 삭제하고 onmouseenteronmouseout이라고 할 수있는 함수를 만들 수 있습니다.

function hoverDot() { 
    document.getElementById('button').style.boxShadow = '0px 0px 0px 0px rgba(0,0,255,0)'; 
    document.getElementById('button').onmouseout = function(){ 
    document.getElementById('button').style.boxShadow = '0px 0px 0px 0px rgba(0,0,255,0)'; 
    } 

    document.getElementById('button').onmouseenter = function(){ 
    document.getElementById('button').style.boxShadow = '0px 0px 0px 30px rgba(0,0,255,1)'; 
    } 
} 

hoverDot(); //intially call hover function 
 

 
function openMenu() { 
 
    document.getElementById('button').style.boxShadow = '0px 0px 0px 100em rgba(0,0,255,1)'; 
 
    setTimeout(showMenu, 500); 
 
} 
 

 
function showMenu() { 
 
    document.getElementById('menu_container').style.visibility = 'visible'; 
 
    document.getElementById('menu_container').style.zIndex = '2'; 
 
    document.getElementById('menu').style.opacity = '1'; 
 
} 
 

 
function closeMenu() { 
 
    document.getElementById('menu').style.opacity = '0'; 
 
    document.getElementById('button').style.boxShadow = '0px 0px 0px 100em rgba(0,0,255,1)'; 
 
    setTimeout(hideMenu, 400); 
 
    setTimeout(hoverDot, 400); //Called function here 
 
} 
 

 
function hideMenu() { 
 
    document.getElementById('menu_container').style.visibility = 'hidden'; 
 
    document.getElementById('menu_container').style.zIndex = '0'; 
 
    document.getElementById('button').style.boxShadow = '0px 0px 0px 0px rgba(0,0,255,1)'; 
 
} 
 

 
function hoverDot() { 
 
    document.getElementById('button').style.boxShadow = '0px 0px 0px 0px rgba(0,0,255,0)'; 
 
    document.getElementById('button').onmouseout = function(){ 
 
    document.getElementById('button').style.boxShadow = '0px 0px 0px 0px rgba(0,0,255,0)'; 
 
    } 
 

 
    document.getElementById('button').onmouseenter = function(){ 
 

 
    document.getElementById('button').style.boxShadow = '0px 0px 0px 30px rgba(0,0,255,1)'; 
 
    } 
 

 
}
<html> 
 

 
<head> 
 
    <title>Design Tests</title> 
 
    <style> 
 
    @import url('https://fonts.googleapis.com/css?family=Raleway:200'); 
 
    #button { 
 
     position: fixed; 
 
     width: 50px; 
 
     height: 50px; 
 
     background-color: blue; 
 
     border-radius: 25px; 
 
     transition-duration: 500ms; 
 
     z-index: 1; 
 
     cursor: pointer; 
 
    } 
 
    
 
    #menu_container { 
 
     position: fixed; 
 
     width: 100%; 
 
     height: 100%; 
 
     top: 0; 
 
     right: 0; 
 
     left: 0; 
 
     bottom: 0; 
 
     background-color: rgba(0, 0, 255, 1); 
 
     z-index: 0; 
 
     visibility: hidden; 
 
    } 
 
    
 
    #menu { 
 
     transition-duration: 500ms; 
 
     opacity: 0; 
 
    } 
 
    
 
    #close_menu { 
 
     color: white; 
 
     font-family: raleway; 
 
     cursor: pointer; 
 
    } 
 
    </style> 
 
</head> 
 

 
<body> 
 
    <div id="button" onclick="openMenu()"></div> 
 
    <div id="menu_container"> 
 
    <div id="menu"> 
 
     <center> 
 
     <h1 id="close_menu" onclick="closeMenu()">CHIUDI</h1> 
 
     </center> 
 
    </div> 
 
    </div> 
 
</body> 
 

 
</html>