2015-06-21 35 views
1

我有這個滑塊,我使用,只要我點擊下一個或上一個按鈕,它以覆蓋我的網站的一些元素的方式轉變。我相信#mask中的問題,我試圖改變一下,但沒有任何區別,對是否導致問題或其他問題有任何想法?和任何解決方案?滑塊壞移位

代碼:

<!DOCTYPE html> 
<html> 

    <head> 
     <meta charset="utf-8"> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
     <title>Gallery</title> 
     <meta name="description" content="An interactive getting started guide for Brackets."> 
     <link rel="stylesheet" href=""> 
<style> 
     body { 
    margin: 0; 
} 
#wrapper { 
    width: 100%; 
    height: 350px; 
    /*position: absolute;*/ 
    top: 0; 
    left: 0; 
    background-color: white; 
    overflow: hidden; 
} 
#nav p { 
    position: absolute; 
    top: 100px; 
    cursor:pointer; 
    color:grey; 

} 
#prev { 
    left: 40px; 
} 
#next { 
    right: 40px; 
} 
#mask { 
    width: 50000px; 
    height: 100%; 
    background-color: white; 
} 
.item { 
    width: 1200px; 
    height: 100%; 
    float: left; 
    background-color: white; 
} 
.content img { 
    height: 100px; 
    width: 17%; 
    float:left; 
    margin-right: 10px; 
    margin-bottom: 10px; 
} 
.content { 
    width: 50%; 
    height: 220px; 
    top: 20%; 
    margin: auto; 
    background-color: white; 
    position: relative; 
} 
.content a { 
    position: relative; 
    top: -17px; 
    left: 170px; 
} 
.selected { 
    background: #fff; 
    font-weight: 700; 
} 
.clear { 
    clear:both; 
} 



     </style> 
    </head> 

    <body> 
<div id="wrapper"> 
    <div id="nav"> 
     <h1><p id="prev">&lt;</p></h1> 
     <h1><p id="next">&gt;</p></h1> 
    </div> 
    <div id="mask"> 
     <div id="item1" class="item"> <a name="item1"></a> 

      <div class="content"> 
       <img id="image1" src="http://placehold.it/350x150" alt="slot1" /> 
       <img id="image2" src="http://placehold.it/350x150" /> 
       <img id="image3" src="http://placehold.it/350x150" /> 
       <img id="image4" src="http://placehold.it/350x150" /> 
       <img id="image5" src="http://placehold.it/350x150" /> 
       <img id="image6" src="http://placehold.it/350x150" /> 
       <img id="image7" src="http://placehold.it/350x150" /> 
       <img id="image8" src="http://placehold.it/350x150" /> 
       <img id="image9" src="http://placehold.it/350x150" /> 
       <img id="image10" src="http://placehold.it/350x150" /> 
      </div> 
     </div> 
     <div id="item2" class="item"> 
      <div class="content"> 
       <img id="image1" src="http://placehold.it/350x150" alt="slot2" /> 
       <img id="image2" src="http://placehold.it/350x150" /> 
       <img id="image3" src="http://placehold.it/350x150" /> 
       <img id="image4" src="http://placehold.it/350x150" /> 
       <img id="image5" src="http://placehold.it/350x150" /> 
       <img id="image6" src="http://placehold.it/350x150" /> 
       <img id="image7" src="http://placehold.it/350x150" /> 
       <img id="image8" src="http://placehold.it/350x150" /> 
       <img id="image9" src="http://placehold.it/350x150" /> 
       <img id="image10" src="http://placehold.it/350x150" /> 
      </div> 
     </div> 
     <div id="item3" class="item"> 
      <div class="content"> 
       <img id="image1" src="http://placehold.it/350x150" alt="slot2" /> 
       <img id="image2" src="http://placehold.it/350x150" /> 
       <img id="image3" src="http://placehold.it/350x150" /> 
       <img id="image4" src="http://placehold.it/350x150" /> 
       <img id="image5" src="http://placehold.it/350x150" /> 
       <img id="image6" src="http://placehold.it/350x150" /> 
       <img id="image7" src="http://placehold.it/350x150" /> 
       <img id="image8" src="http://placehold.it/350x150" /> 
       <img id="image9" src="http://placehold.it/350x150" /> 
       <img id="image10" src="http://placehold.it/350x150" /> 
      </div> 
     </div> 
    </div> 
</div> 






<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

<script> 
$(document).ready(function() { 
    var newItem = 0; 
    var itemCount = $('.item').length; 

    function shift(direction) { 
     var $mask = $('#mask'), 
      $items = $('.item'), 
      currentItem = $mask.data('currentItem'); 

     if (currentItem === undefined) { 
      currentItem = 0; 
     } 

     $mask.data('currentItem', newItem).animate({ 
      marginLeft: -newItem * $items.eq(0).width() 
     }); 
    } 

    $('#prev').click(function() { 
     if (newItem === 0) { 
      newItem = itemCount - 1; 
     } else { 
      newItem--; 
     } 
     return shift(); 
    }); 
    $('#next').click(function() { 
     if (newItem === itemCount - 1) { 
      newItem = 0; 
     } else { 
      newItem++; 
     } 
     return shift(); 
    }); 

    function resizePanel() { 
     width = $(window).width(); 
     height = $(window).height(); 

     $('#wrapper, .item').css({ 
      width: width, 
      height: height 
     }); 
    } 

    $(window).resize(function() { 
     resizePanel(); 
    }); 
    resizePanel(); 
}); 
     </script> 
    </body> 
</html> 

的jsfiddle:https://jsfiddle.net/ew98y5fv/

+0

您的jsfiddle不含任何其他元素,所以不能說是什麼問題。請你能給你的小提琴添加另一個元素來演示你的問題嗎? –

+0

@ArathiSreekumar看到分隔線在消失前轉移到最終的左/右的方式。所以他們正在傳遞頁面中的其他元素 – mikeb

+0

我想你在問一個問題之前關於一些導航單元。所以這裏的答案是相似的。我會嘗試添加一些代碼來演示。您需要將滑塊邏輯與頁面的其餘部分分開。 –

回答

2

我已經修改了你HTML:

<body> 
<div id="wrapper"> 
    <div id="slider-container"> 
     <div id="nav"> 
      <p id="prev">&lt;</p> 
      <p id="next">&gt;</p> 
     </div> 
     <div class="slider-view-area"> 
      <div id="mask"> 
       <div id="item1" class="item"> <a name="item1"></a> 

        <div class="content"> 
         <img id="image1" src="http://placehold.it/350x150" alt="slot1" /> 
         <img id="image2" src="http://placehold.it/350x150" /> 
         <img id="image3" src="http://placehold.it/350x150" /> 
         <img id="image4" src="http://placehold.it/350x150" /> 
         <img id="image5" src="http://placehold.it/350x150" /> 
         <img id="image6" src="http://placehold.it/350x150" /> 
         <img id="image7" src="http://placehold.it/350x150" /> 
         <img id="image8" src="http://placehold.it/350x150" /> 
         <img id="image9" src="http://placehold.it/350x150" /> 
         <img id="image10" src="http://placehold.it/350x150" /> 
        </div> 
       </div> 
       <div id="item2" class="item"> 
        <div class="content"> 
         <img id="image1" src="http://placehold.it/350x150" alt="slot2" /> 
         <img id="image2" src="http://placehold.it/350x150" /> 
         <img id="image3" src="http://placehold.it/350x150" /> 
         <img id="image4" src="http://placehold.it/350x150" /> 
         <img id="image5" src="http://placehold.it/350x150" /> 
         <img id="image6" src="http://placehold.it/350x150" /> 
         <img id="image7" src="http://placehold.it/350x150" /> 
         <img id="image8" src="http://placehold.it/350x150" /> 
         <img id="image9" src="http://placehold.it/350x150" /> 
         <img id="image10" src="http://placehold.it/350x150" /> 
        </div> 
       </div> 
       <div id="item3" class="item"> 
        <div class="content"> 
         <img id="image1" src="http://placehold.it/350x150" alt="slot2" /> 
         <img id="image2" src="http://placehold.it/350x150" /> 
         <img id="image3" src="http://placehold.it/350x150" /> 
         <img id="image4" src="http://placehold.it/350x150" /> 
         <img id="image5" src="http://placehold.it/350x150" /> 
         <img id="image6" src="http://placehold.it/350x150" /> 
         <img id="image7" src="http://placehold.it/350x150" /> 
         <img id="image8" src="http://placehold.it/350x150" /> 
         <img id="image9" src="http://placehold.it/350x150" /> 
         <img id="image10" src="http://placehold.it/350x150" /> 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 
</body> 

這裏是CSS:

body { 
    margin: 0; 
} 
#wrapper { 
    background-color: blue; 
    padding: 20px 0; 
} 

#slider-container { 
    padding: 20px 50px; 
    height: 350px; 
    background-color: white; 
    overflow: hidden; 
    position: relative; 
} 

.slider-view-area { 
    overflow: hidden; 
} 

#nav p { 
    position: absolute; 
    top: 100px; 
    cursor:pointer; 
    color:grey; 

} 
#prev { 
    left: 20px; 
    font-size: 30px; 
} 
#next { 
    right: 20px; 
    font-size: 30px; 
} 
#mask { 
    width: 50000px; 
    height: 100%; 
    background-color: white; 
} 
.item { 
    width: 1200px; 
    height: 100%; 
    float: left; 
    background-color: white; 
} 
.content img { 
    height: 100px; 
    width: 17%; 
    float:left; 
    margin-right: 10px; 
    margin-bottom: 10px; 
} 
.content { 
    width: 50%; 
    height: 220px; 
    top: 20%; 
    margin: auto; 
    background-color: white; 
    position: relative; 
} 
.content a { 
    position: relative; 
    top: -17px; 
    left: 170px; 
} 
.selected { 
    background: #fff; 
    font-weight: 700; 
} 
.clear { 
    clear:both; 
} 

我身邊取出H1標籤你的 導航元素,因爲您不應該使用標題標籤來顯示更改,例如使圖標看起來更大。爲此,你應該使用CSS。在這種情況下,h1標記在語義上不正確,因爲導航元素不是主標題。

我剛剛去了一個快速修復。但是,如果您想將滑塊設置爲頁面中的獨立組件,則應選擇其方向。

這裏是的jsfiddle:https://jsfiddle.net/ew98y5fv/3/

+0

感謝您的幫助。但是有一個問題,如果我重新調整JSfiddle中的結果標籤的大小,除了當前的其他分頻器出現。爲什麼? – mikeb

+0

調整大小時,您將窗口寬度設置爲包裝和項目。我不知道這個的目的,因爲寬度無論如何都是100%。但這可能與這種行爲有關。 –

+0

我應該刪除此功能嗎? – mikeb