2015-11-03 126 views
2

這裏是我的codepen:http://codepen.io/Chiz/pen/MaBwBb按鈕不可點擊?

當你點擊按鈕,一般按鈕會給被「按下」視覺反饋,但在這種情況下,沒有這樣的事情發生。這就像按鈕已被禁用。爲什麼是這樣?

$(document).ready(function() { 
 
    $("#fullpage").fullpage({ 
 
    verticalCentered: false, 
 
    resize: true, 
 
    scrollingSpeed: 700, 
 
    css3: true, 
 
    easing: "easeOutBounce" 
 
    }); 
 
});
* { 
 
    box-sizing: border-box; 
 
} 
 
html, 
 
body { 
 
    height: 100%; 
 
} 
 
div.container { 
 
    position: relative; 
 
} 
 
#fullpage { 
 
    width: 100%; 
 
    height: 100%; 
 
    background-color: #ffe4b3; 
 
} 
 
#header { 
 
    width: 100%; 
 
    height: 70px; 
 
    line-height: 70px; 
 
    background-color: #343434; 
 
} 
 
#header ul { 
 
    list-style-type: none; 
 
    color: white; 
 
    margin: 0; 
 
    height: 100%; 
 
} 
 
#header ul li { 
 
    display: inline-block; 
 
    float: right; 
 
    padding: 0rem 2rem; 
 
    width: 10rem; 
 
    height: 100%; 
 
    text-align: center; 
 
    font-size: 1rem; 
 
} 
 
#header ul li a { 
 
    color: white; 
 
    text-decoration: none; 
 
} 
 
#footer { 
 
    width: 100%; 
 
    height: 50px; 
 
    position: absolute; 
 
    bottom: 0px; 
 
    background-color: black; 
 
} 
 
.slide { 
 
    font-size: 1.5rem; 
 
} 
 
.button-container { 
 
    position: absolute; 
 
    left: 50%; 
 
    top: 50%; 
 
    transform: translate(-50%, -50%); 
 
} 
 
.prev, 
 
.next { 
 
    width: 7rem; 
 
    height: 3rem; 
 
    font-size: 1rem; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> 
 
<script src="https:https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script> 
 
<script src="https:https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.7.4/jquery.fullPage.min.js"></script> 
 
<script src="https:https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.7.4/vendors/jquery.slimscroll.min.js"></script> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.7.4/jquery.fullPage.min.css" /> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css" /> 
 

 

 

 
<div id="fullpage"> 
 
    <div class="section active container"> 
 
    <div id="header"> 
 
     <ul> 
 
     <li><a href="">Link 1</a> 
 
     </li> 
 
     <li><a href="">Link 2</a> 
 
     </li> 
 
     <li><a href="">Link 3</a> 
 
     </li> 
 
     </ul> 
 
    </div> 
 
    <div class="slide">Slide1</div> 
 
    <div class="slide">Slide2</div> 
 
    <div class="slide">Slide3</div> 
 

 
    <div class="button-container"> 
 
     <button type="button" class="prev">Prev</button> 
 
     <button type="button" class="next">Next</button> 
 
    </div> 
 

 
    <div id="footer"></div> 
 
    </div> 
 
</div>

+4

它在chrome中工作您使用哪種瀏覽器? – guradio

+1

它看起來像你的按鈕背後「。幻燈片」。添加「z-index:2;」到「.button-container」解決了這個問題。 – musse1

+1

查看此演示http://codepen.io/anon/pen/YyjEmX –

回答

6

因爲你定位元素的方式,一些堆疊順序的超出,因此幻燈片單擊事件實際發生在那些2個按鈕的上方。

嘗試添加z-index: 999;,您將看到您期待回來的功能。

CodePen Example

$(document).ready(function() { 
 
    $("#fullpage").fullpage({ 
 
    verticalCentered: false, 
 
    resize: true, 
 
    scrollingSpeed: 700, 
 
    css3: true, 
 
    easing: "easeOutBounce" 
 
    }); 
 
});
* { 
 
    box-sizing: border-box; 
 
} 
 
html, 
 
body { 
 
    height: 100%; 
 
} 
 
div.container { 
 
    position: relative; 
 
} 
 
#fullpage { 
 
    width: 100%; 
 
    height: 100%; 
 
    background-color: #ffe4b3; 
 
} 
 
#header { 
 
    width: 100%; 
 
    height: 70px; 
 
    line-height: 70px; 
 
    background-color: #343434; 
 
} 
 
#header ul { 
 
    list-style-type: none; 
 
    color: white; 
 
    margin: 0; 
 
    height: 100%; 
 
} 
 
#header ul li { 
 
    display: inline-block; 
 
    float: right; 
 
    padding: 0rem 2rem; 
 
    width: 10rem; 
 
    height: 100%; 
 
    text-align: center; 
 
    font-size: 1rem; 
 
} 
 
#header ul li a { 
 
    color: white; 
 
    text-decoration: none; 
 
} 
 
#footer { 
 
    width: 100%; 
 
    height: 50px; 
 
    position: absolute; 
 
    bottom: 0px; 
 
    background-color: black; 
 
} 
 
.slide { 
 
    font-size: 1.5rem; 
 
} 
 
.button-container { 
 
    position: absolute; 
 
    left: 50%; 
 
    top: 50%; 
 
    transform: translate(-50%, -50%); 
 
    z-index: 999; 
 
} 
 
.prev, 
 
.next { 
 
    width: 7rem; 
 
    height: 3rem; 
 
    font-size: 1rem; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> 
 
<script src="https:https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script> 
 
<script src="https:https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.7.4/jquery.fullPage.min.js"></script> 
 
<script src="https:https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.7.4/vendors/jquery.slimscroll.min.js"></script> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.7.4/jquery.fullPage.min.css" /> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css" /> 
 

 

 

 
<div id="fullpage"> 
 
    <div class="section active container"> 
 
    <div id="header"> 
 
     <ul> 
 
     <li><a href="">Link 1</a> 
 
     </li> 
 
     <li><a href="">Link 2</a> 
 
     </li> 
 
     <li><a href="">Link 3</a> 
 
     </li> 
 
     </ul> 
 
    </div> 
 
    <div class="slide">Slide1</div> 
 
    <div class="slide">Slide2</div> 
 
    <div class="slide">Slide3</div> 
 

 
    <div class="button-container"> 
 
     <button type="button" class="prev">Prev</button> 
 
     <button type="button" class="next">Next</button> 
 
    </div> 
 

 
    <div id="footer"></div> 
 
    </div> 
 
</div>

+0

Tks,這個工程!順便說一句,你怎麼知道按鈕在.fpslides下?你用過某種真棒調試器嗎? – Xeon

+1

當我嘗試使用Chrome檢查器將鼠標懸停在元素上時,我無法選擇它們,表明它們隱藏在另一圖層下。我有很多以前的職位經驗,其中一個解決方案通常是'z-index'。沒有什麼可怕的或神奇的,只是以前的經驗:) – Stewartside

2

你有.fp-slides.button-container。應用z-index對於.button-container大於z-index.fp-slides