2014-07-18 2 views
-1

HTML :슬라이드

<div class="inline-wrapper"> 
    <div class="inline-blocks" id="f">123</div> 
    <div class="inline-blocks" id="s">123</div> 
    <div class="inline-blocks" id="t">123</div> 
    <div class="inline-blocks" id="fo">123</div> 
</div> 

CSS :

html, body { 
    width: 100%; 
    height: 100%; 
/* overflow: hidden;*/ 
} 

.inline-wrapper{ 
    width: 400%; 
    height: 100%; 
    font-size: 0; 
    position: relative; 
} 

.inline-blocks{ 
    display: inline-block; 
    width: 25%; 
    height: 100%; 
    vertical-align: top; 
    position: relative; 
} 

>.inline-blocks:nth-child(1){ 
    background-color: #000; 
} 

.inline-blocks:nth-child(2){ 
    background-color: blue; 
} 

.inline-blocks:nth-child(3){ 
    background-color: red; 
} 

.inline-blocks:nth-child(4){ 
    background-color: green; 
} 

은 어떻게 ID없이 밀어 수 있습니까? 이것은 실제로 슬라이더의 작업입니다. 그러나 나는 그 논리를 이해할 수 없다. ID없이 뒤집는 방법을 알고 싶습니다. 블록을 검사하여 현재 클래스를 제공해야합니다.

+2

당신이 "슬라이드"무엇을 의미합니까? – jtheletter

+0

질문에 대해 자세히 설명해주십시오 ... 어디로 밀어 넣으시겠습니까? 당신은 그들이 왼쪽과 오른쪽으로 스크롤하기를 원한다는 뜻입니까? 또한 "ID없이 뒤집기"란 무엇을 의미합니까? 각각의'.inline-blocks'의 뒤집기 애니메이션을 만들고 싶습니까? – Marquizzo

+0

당신은 요소를 뒤집기 위해'jQuery Cycle' 플러그인을 사용할 수 있습니다. http://jquery.malsup.com/cycle/ – lokeshpahal

답변

1

자동 슬라이드

HTML :

<div class="inline-wrapper"> 
    <div class="inline-blocks" id="f">123</div> 
    <div class="inline-blocks" id="s">123</div> 
    <div class="inline-blocks" id="t">123</div> 
    <div class="inline-blocks" id="fo">123</div> 
</div> 

jQuery를 :

(function() { 
    var numDivs = $('.inline-wrapper').children().length; //Count children ELements 
    var counter = 1; 

    function slide(time, counter) { 
     var $currentDiv = $('.inline-wrapper .inline-blocks:nth-child(' + counter + ')'); //get next element 
     var position = $currentDiv.position(); //get position of next element 

     if (numDivs > 1) { 
      $('html,body').animate({ 
       scrollLeft: position.left 
      }, time/2); //Animate to next element 
     } 
    }; 

    $('.inline-blocks').on('click', function() { 
     counter = counter + 1; 
     slide(2000, counter); 
    }); 
})(); 

DEMO

+0

고맙습니다. 더 이해하기 쉬워진다. 하지만 우리는 그렇게 쓰면 안됩니다 - + counter +1 +? 그리고 저는 클릭 기능을 구현하려고합니다. 왜 오버 플로우가 숨겨져 작동하지 않았습니까? – IFier

+0

'i ++'http://stackoverflow.com/questions/7313710/why-do-people-use-ii-1-instead-of-i – alexP

+0

오버플로 숨김 : http://stackoverflow.com/questions/11301841/how -to-scroll-within-overflow-hidden-div-to-a-certain-currently-invisible-ele – alexP

관련 문제