2017-03-28 4 views
1

현재 링크를 클릭하면 내 제목이 슬라이드되도록합니다. 링크를 클릭하면 새 제목이 들어가기 전에 현재 제목이 슬라이드 아웃되도록하려면 어떻게해야합니까?CSS 애니메이션과 자바 스크립트 사용하기

이것은 내가 사용하고있는 클릭 이벤트입니다. 그것은 모두 어색 할 수도 있습니다, 나는 그것을 시도하고 작동하도록 다른 것들을 추가했습니다.

// list of sections. the first section contains only the h1. 
var sections = document.querySelectorAll("section"); 

function hideSections() { 
    for (var i = 0; i < sections.length; i++) { 
    sections[i].className = "hidden"; 
    } 
} 

// list of links in the nav. 
var links = document.querySelector("nav").querySelectorAll("a"); 

// add listeners to those links 
for (var i = 0; i < links.length; i++) { 
    links[i].addEventListener("click", clicked); 
} 

function clicked(event) { 
    var target = document.querySelector('h2'); 
    target.className = "slideout"; 

    event.preventDefault(); 
    hideSections(); 

    var current = event.target.hash; 
    // "show" appropriate selection, based on id from link 
    document.querySelector(current).className = ""; 

    // modify URL to reflect current location 
    location.hash = current; 

    target.addEventListener("animationend", newfile); 

    function newfile() { 
    target.removeEventListener("animationend", newfile); 
    } 
    target.addEventListener("animationstart", newfile); 

} 

// when page loads... 
hideSections(); 

if (location.hash == "") { 
    sections[0].className = ""; 
} else { 
    document.querySelector(location.hash).className = ""; 
} 

https://jsfiddle.net/yk7w2zt2/ 여기 내 전체 코드입니다.

+0

당신은 당신이 디스플레이와 함께이 일을하고 있기 때문에 당신이 원하지 않는 제목과 내용을 숨기고하고 있습니다 클릭보고되지 않은 : 어떤 애니메이션이없는 것도 있습니다. – user3094755

답변

관련 문제