2013-10-01 2 views
0

enter image description here 내가 만든 CSS 슬라이더의 탐색 모음을 만들고 싶습니다.순수 CSS 슬라이더의 탐색 모음을 만드는 방법은 무엇입니까?

Here 당신이 볼 수있는 라이브 데모입니다.

그리고 나는 또한 수평으로 이미지를 슬라이드 싶어,

내가 이것을 달성 할 수있는 방법 어떤 생각?

내가 완전한 코드를 게시 할 때 오류가 표시되어 여기에 CSS의 완전한 코딩을 추가했습니다. jsfiddle 이미지가 표시되지 않을까 걱정하지 마십시오.하지만 코딩이 완벽합니다.

HTML

<div class="container"> 
    <div id="content-slider"> 
     <div id="slider"> 
      <div id="mask"> 
      <ul> 
      <li id="first" class="firstanimation"> 
        <a href="#"> 
         <img src="images/img_1.jpg" alt="Cougar"/> 
        </a> 
        <div class="tooltip"> 
         <h1>Cougar</h1> 
        </div> 
       </li> 

       <li id="second" class="secondanimation"> 
        <a href="#"> 
         <img src="images/img_2.jpg" alt="Lions"/> 
        </a> 
        <div class="tooltip"> 
         <h1>Lions</h1> 
        </div> 
       </li> 

       <li id="third" class="thirdanimation"> 
        <a href="#"> 
         <img src="images/img_3.jpg" alt="Snowalker"/> 
        </a> 
        <div class="tooltip"> 
         <h1>Snowalker</h1> 
        </div> 
       </li> 

       <li id="fourth" class="fourthanimation"> 
        <a href="#"> 
         <img src="images/img_4.jpg" alt="Howling"/> 
        </a> 
        <div class="tooltip"> 
         <h1>Howling</h1> 
        </div> 
       </li> 

       <li id="fifth" class="fifthanimation"> 
        <a href="#"> 
         <img src="images/img_5.jpg" alt="Sunbathing"/> 
        </a> 
        <div class="tooltip"> 
         <h1>Sunbathing</h1> 
        </div> 
       </li> 
       </ul> 
      </div> 
     <div class="progress-bar"></div> 
     </div> 
    </div> 
</div> 

CSS

html, body { 
    background: #eaeaea url(../img/bg.png) repeat; 
    font-size: 12px; 
    font-family: "Open Sans", serif; 
    min-width: 960px; 
    margin: 0; 
    padding: 0; 
    color: #aaa; 
} 

.content h1 { 
    font-size: 48px; 
    color: #000; 
    text-shadow: 0px 1px 1px #f4f4f4; 
    text-align: center; 
    padding:60px 0 30px; 
} 

/* LAYOUT */ 
.container { 
    margin: 0 auto; 
    overflow: hidden; 
    width: 960px; 
} 

/* CONTENT SLIDER */ 
#content-slider { 
    width: 100%; 
    height: 360px; 
    margin: 10px auto 0; 
} 
/* SLIDER */ 
#slider { 
    background: #000; 
    border: 5px solid #eaeaea; 
    box-shadow: 1px 1px 5px rgba(0,0,0,0.7); 
    height: 320px; 
    width: 680px; 
    margin: 40px auto 0; 
    overflow: visible; 
    position: relative; 
} 
#mask { 
    overflow: hidden; 
    height: 320px; 
} 
#slider ul { 
    margin: 0; 
    padding: 0; 
    position: relative; 
} 
#slider li { 
    width: 680px; 
    height: 320px; 
    position: absolute; 
    top: -325px; 
    list-style: none; 
} 

#slider li.firstanimation { 
    -moz-animation: cycle 25s linear infinite; 
    -webkit-animation: cycle 25s linear infinite;   
} 
#slider li.secondanimation { 
    -moz-animation: cycletwo 25s linear infinite; 
    -webkit-animation: cycletwo 25s linear infinite;  
} 
#slider li.thirdanimation { 
    -moz-animation: cyclethree 25s linear infinite; 
    -webkit-animation: cyclethree 25s linear infinite;  
} 
#slider li.fourthanimation { 
    -moz-animation: cyclefour 25s linear infinite; 
    -webkit-animation: cyclefour 25s linear infinite;   
} 
#slider li.fifthanimation { 
    -moz-animation: cyclefive 25s linear infinite; 
    -webkit-animation: cyclefive 25s linear infinite;   
} 

#slider .tooltip { 
    background: rgba(0, 0, 0, 0.7); 
    width: 300px; 
    height: 60px; 
    position: relative; 
    bottom: 75px; 
    left: -320px; 
    -moz-transition: all 0.3s ease-in-out; 
    -webkit-transition: all 0.3s ease-in-out; 
} 
#slider .tooltip h1 { 
    color: #fff; 
    font-size: 24px; 
    font-weight: 300; 
    line-height: 60px; 
    padding: 0 0 0 20px; 
} 
#slider li#first:hover .tooltip, 
#slider li#second:hover .tooltip, 
#slider li#third:hover .tooltip, 
#slider li#fourth:hover .tooltip, 
#slider li#fifth:hover .tooltip { 
    left: 0px; 
} 
#slider:hover li, 
#slider:hover .progress-bar { 
    -moz-animation-play-state: paused; 
    -webkit-animation-play-state: paused; 
} 

/* PROGRESS BAR */ 
.progress-bar { 
    position: relative; 
    top: -5px; 
    width: 680px; 
    height: 5px; 
    background: #000; 
    -moz-animation: fullexpand 25s ease-out infinite; 
    -webkit-animation: fullexpand 25s ease-out infinite; 
} 
+0

목표로하는 탐색 유형에 대한 설명을 추가 할 수 있습니까? 아마도 사진과 탐색 자체에서의 시도가 있을까요? 그리고 당신은 그것이 항상 수평 적으로 혹은 약간의 시간으로 항상 전환되기를 원합니 까? –

+0

예 슬라이더의 탐색을 볼 수있는 사진을 추가했으며 슬라이더의 데모를 넣은 jsfiddle에서 볼 수있는 것처럼 확실한 전환을 추가했습니다. –

+0

순수한 CSS에서 그런 일을 할 이유가 없습니다. 그것은 지나치게 길고, 거의 유지할 수 없으며 당신이 상상할 수있는 다른 모든 나쁜 단어들입니다. 당신이 CSS의 300 라인에서 원하는 것은 JS 20 라인 미만이 필요하다. jQuery –

답변

0

는 단순히 내가 Word 및 사용에 이상 복사합니다 (애니메이션에서 top 값과 #slider lileft로의 변경 가로로 스크롤하려면 거기에 대체 기능), . 다른 방법으로 스크롤하려면 leftright으로 변경하십시오. Demo of that

"무선"버튼을 사용할 모양을 선택하십시오. 당신이 순수 CSS로 원하는 것을 할 불가능를인지는 모르겠지만,이 애니메이션은 쉽게 자바 스크립트와

의 어떤 미친 조작을 것이지만, CSS 애니메이션은 여전히 ​​어렵습니다. 잠시 생각한 후에 애니메이션의 클래스 이름에 의존하는 this solution (버그가있는 버전, 더 나은 버전을 찾으십시오)을 생각해 냈습니다.

더 좋은 작업을 한 후에 다음 그림으로의 전환이 포함 된 솔루션을 제시 할 수있었습니다. which can be found here! 지금은 상당히 많은 작업이지만 댓글로 이해하기 쉽기를 바랍니다. 나는 당신이 더 이상 순수한 CSS로 그것을 할 수 있다고 확신하지 못한다.

내가 작성한 자바 스크립트는 아마도 일부 단축 될 수 있었고, 너무 효율적으로 만드는 데 너무 많은 시간을 투자하지 않았습니다. 내가 본 유일한 오류는 첫 번째 라디오 클릭에 짧은 검은 색 공간이 있으며 너무 빨리 클릭하면 전환이 없습니다. 나는 그것이 당신의 필요에 어울리기를 바랍니다! 여기

최종 버전에 추가 된 코드는 바로 위의 발견 :

/* Javascript */ 
// Obtain the objects within javascript to use 
var slider = document.getElementById('slider'), 
    one = document.getElementsByClassName('firstanimation')[0], 
    two = document.getElementsByClassName('secondanimation')[0], 
    three = document.getElementsByClassName('thirdanimation')[0], 
    four = document.getElementsByClassName('fourthanimation')[0], 
    five = document.getElementsByClassName('fifthanimation')[0], 
    // Hidden element that a 5s animation is applied to 
    hidden = document.getElementById('hidden'), 
    // Create an array of the li elements to make manipulating easier 
    liArray = [one, two, three, four, five], 
    // Obtain the radio buttons 
    radios = document.getElementsByName('picture'), 
    // For optimization and easy access later on 
    liNum = liArray.length, 
    // The bar at the bottom 
    progress = document.getElementById('progress-bar'), 
    // The li currently showing 
    currNum, 
    // Prefixes for the PrefixedEvent function 
    pfx = ["webkit", "moz", "MS", "o", ""]; 

// Give each radio button an onclick function 
for(var i = 0; i < liNum; i++) { 
    // The following line is necessary to prevent them all from being 5 
    radios[i].i = i; 
    radios[i].onclick = function() { changePic(this.i) }; 
} 

// Changes the radio every time a slide animates to the left 
PrefixedEvent(hidden, 'AnimationIteration', function() { 
    for(var i = 0; i < liNum; i++) { 
     // Checks to see which is checked 
     if(radios[i].checked) { 
      // Uncheckds the checked one 
      radios[i].checked = false; 
      // Checks the next one (first if there is no next one) 
      if(i + 1 < liNum) { 
       radios[i + 1].checked = true; 
      } else { 
       radios[0].checked = true; 
      } 
      break; 
     } 
    } 
}); 

// Makes using animationiteration easier cross-browser 
function PrefixedEvent(element, type, callback) { 
    for (var p = 0; p < pfx.length; p++) { 
     if (!pfx[p]) type = type.toLowerCase(); 
     element.addEventListener(pfx[p]+type, callback, false); 
    } 
} 

// Transitions from one slide to the clicked one, sets new animation order based on choice 
function changePic(nextNum) { 
    // Gets the li being displayed currently 
    for(var j = 0; j < liNum; j ++) { 
     var computedStyle = window.getComputedStyle(liArray[j]), 
      rightPos = computedStyle.getPropertyValue('right'); 
     if(rightPos == "0px") { 
      currNum = j; 
      break; 
     } 
    } 

    // Removes the animations for all the slider elements 
    one.className = ''; 
    two.className = ''; 
    three.className = ''; 
    four.className = ''; 
    five.className = ''; 
    hidden.className = ''; 
    progress.className = ''; 

    // Checks to see if it's a different element 
    if(nextNum != currNum) 
    { 
     // If it is, animate the new one in from the right, slide current to left 
     liArray[nextNum].style.right = "-685px";   
     liArray[currNum].style.right = "0px";   

     liArray[nextNum].style.right = "0px"; 
     liArray[currNum].style.right = "685px";   
    } else { 
     // If it's not, leave it 
     liArray[currNum].style.right = "0px"; 
    } 

    // Necessary to initialize another animation (known CSS flaw) 
    setTimeout(function() { 
     // Resets animation order based on the clicked radio 
     if(nextNum == 0) { 
      one.className = 'firstanimation'; 
      two.className = 'secondanimation'; 
      three.className = 'thirdanimation'; 
      four.className = 'fourthanimation'; 
      five.className = 'fifthanimation';  
      hidden.className = 'timer'; 
      progress.className = 'progress'; 
     } 
     if(nextNum == 1) { 
      one.className = 'fifthanimation'; 
      two.className = 'firstanimation'; 
      three.className = 'secondanimation'; 
      four.className = 'thirdanimation'; 
      five.className = 'fourthanimation';  
      hidden.className = 'timer'; 
      progress.className = 'progress'; 
     } 
     if(nextNum == 2) { 
      one.className = 'fourthanimation'; 
      two.className = 'fifthanimation'; 
      three.className = 'firstanimation'; 
      four.className = 'secondanimation'; 
      five.className = 'thirdanimation';  
      hidden.className = 'timer'; 
      progress.className = 'progress'; 
     } 
     if(nextNum == 3) { 
      one.className = 'thirdanimation'; 
      two.className = 'fourthanimation'; 
      three.className = 'fifthanimation'; 
      four.className = 'firstanimation'; 
      five.className = 'secondanimation'; 
      hidden.className = 'timer'; 
      progress.className = 'progress'; 
     } 
     if(nextNum == 4) { 
      one.className = 'secondanimation'; 
      two.className = 'thirdanimation'; 
      three.className = 'fourthanimation'; 
      four.className = 'fifthanimation'; 
      five.className = 'firstanimation';  
      hidden.className = 'timer'; 
      progress.className = 'progress'; 
     }   

     // Moves the previous image to the right with the rest 
     liArray[currNum].style.right = "-685px"; 

    }, 500 /* Transition length in milliseconds */); 
} 

/* Added HTML */ 
<!-- Under #slider and #mask... --> 
<li id="hidden" class='timer'></li> 

<!-- Under #content-slider... --> 
<nav id='photoNav'> 
    <input type="radio" name="picture" checked="true" id="navOne" /> 
    <input type="radio" name="picture" id="navTwo" /> 
    <input type="radio" name="picture" id="navThree" /> 
    <input type="radio" name="picture" id="navFour" /> 
    <input type="radio" name="picture" id="navFive" /> 
</nav> 

/* Added CSS */ 
#hidden { 
    visibility: hidden; 
    pointer-events:none;  
} 
#hidden.timer { 
    -mos-animation: nothing 5s linear infinite; 
    -webkit-animation: nothing 5s linear infinite; 
    animation: nothing 5s linear infinite; 
} 
#photoNav { 
    position: absolute; 
    top: 300px; 
    left:480px;  
    margin-left: -60px; 
    cursor:pointer; 
} 
#photoNav input { 
    cursor:pointer; 
} 
#progress-bar { 
    position:relative; 
    top:-5px; 
    width:680px; 
    height:5px; 
    background:#000; 
} 
#progress-bar.progress { 
    -moz-animation:fullexpand 25s ease-out infinite; 
    -webkit-animation:fullexpand 25s ease-out infinite; 
    animation:fullexpand 25s ease-out infinite; 
} 
@-moz-keyframes nothing { 0% {} 100% {} } 
@-webkit-keyframes nothing { 0% {} 100% {} } 
@keyframes nothing { 0% {} 100% {} } 

/* And some other smaller things not worth the space */ 
는 자바 스크립트와 함께 할 그냥 쉽게 될 거라고 말할 필요도없이

하지만 좋은 연습과 재미뿐만 아니라 수행했다 https://github.com/drygiel/csslider

당신이 왼쪽 여백을 애니메이션 CSS 애니메이션을 사용할 필요가 자동 변경 이미지를 원하는 경우

+0

당신은 잘 일했지만, 순수한 CSS로 해결책을 찾고있다. 누구든지이 일을 잘할 수 있다면 :) 아무도 대답하지 않으면 받아 들일 수있을 것입니다. –

+0

클릭하면 슬라이드 사이에 어떤 유형의 전환이 생기고 싶다면 순수한 CSS 솔루션에 가깝지 않습니다. 그럴까요? –

+0

슬라이더를 나타내는 왼쪽 및 오른쪽 화살표가있는 버튼을 추가 할 수 있습니까? –

0

은 여기에서 순수 CSS 슬라이더가 있습니다.

+0

위대한 :) 좋은 작품. –

관련 문제