2015-11-07 72 views
3

我設計下一個先前圖標貓頭鷹旋轉木馬第二版是這樣的:下一個先前圖標貓頭鷹轉盤無法正常工作2

HTML:

<section id="jm-Section-CARU"> 
    <!-- CAROUSEL NAV --> 
    <nav class="next"> <a class="customNextBtn" href="#">&nbsp;</a> 

    </nav> 
    <nav class="prev" style="display:none;"> <a class="customPrevBtn" href="#">&nbsp;</a> 

    </nav> 
    <!-- END NAV --> 
    <div class="owl-carousel" id="owl-example"> 
     <div class="item"> 
      <img src="http://placehold.it/500x300" alt="The Last of us"> 
     </div> 
     <div class="item"> 
      <img src="http://placehold.it/500x300" alt="The Last of us"> 
     </div> 
     <div class="item"> 
      <img src="http://placehold.it/500x300" alt="The Last of us"> 
     </div> 
    </div> 
</section> 

CSS:

#jm-Section-CARU { 

     position: relative; 

     margin: 0; 

     text-align: center; 

     width:500px; 

     height:300px; 

    } 

    .next, .prev { 

     display: none; 

     position: absolute; 

     top: calc(50% - 18px); 

     z-index: 3; 

     height: 36px; 

     width: 36px; 

     background: rgba(255, 255, 255, 0.74); 

    } 

    .next:hover, .prev:hover { 

     background: rgba(255, 255, 255, 0.94); 

    } 

    .next { 

     right: 0; 

    } 

    .prev { 

     left: 0; 

    } 

    .prev a { 

     display: inherit; 

     -ms-transform: rotate(270deg); 

     -webkit-transform: rotate(270deg); 

     transform: rotate(270deg); 

     background: url("http://cdn.flaticon.com/img/avatar/5.jpg") center no-repeat; 

     width: 32px; 

     height: 34px; 

    } 

    .next a { 

     display: inherit; 

     -ms-transform: rotate(90deg); 

     -webkit-transform: rotate(90deg); 

     transform: rotate(90deg); 

     background: url("http://cdn.flaticon.com/img/avatar/5.jpg") center no-repeat; 

     width: 32px; 

     height: 40px; 

     float: right; 

    } 

    .owl-theme .owl-controls { 

     position: absolute; 

     margin: 0; 

     width: 100%; 

     bottom: -9%; 

    } 

    .owl-theme .owl-dots .owl-dot span { 

     background-color: rgba(170, 170, 170, 0.88); 

     height: 8px; 

     width: 8px; 

    } 

    .owl-theme .owl-dots .owl-dot.active span, .owl-theme .owl-dots .owl-dot.active:hover span { 

     background-color: rgba(0, 0, 0, 0.88); 

    } 

    .owl-theme .owl-dots .owl-dot:hover span { 

     background-color: rgba(51, 51, 51, 0.88); 

    } 

    .owl-item { 

     z-index:1; 

     /* Fix for OwlCarousel2 Issue #772 (loop flicker) */ 

    } 

JS:

function showNav(e) { 
    if ($(".next").css("float") == "right") { 
     $(".next").fadeIn(); 
     $(".prev").fadeIn(); 
    } 
} 

function hideNav(e) { 
    $(".next").fadeOut(); 
    $(".prev").fadeOut(); 
} 
$("#jm-Section-CARU").hover(showNav, hideNav); 
$('.customNextBtn').click(function (e) { 
    e.preventDefault(); 
    $("#owl-example").trigger('next.owl.carousel'); 
}); 
$('.customPrevBtn').click(function (e) { 
    e.preventDefault(); 
    $("#owl-example").trigger('prev.owl.carousel'); 
}); 
$("#owl-example").owlCarousel({ 
    items: 1 
}); 

但是在行動next and prev icon不顯示在部分懸停和不工作。

如何解決這個問題?

DEMO HERE

回答

0

$(".next").css("float") == "right"語句返回沒有因爲每次在你的CSS你寫:.next {right:0;}將其更改爲.next {float:right;right:0;}和你的代碼應該工作。然而, 聲明有點不必要,您不需要檢查它是否正確浮動,因爲您的方法showNav每次將鼠標懸停在圖像上時都會運行。正如darshanags所說,刪除$(".next").css("float") == "right"聲明,我認爲你會得到更好的結果:)

相關問題