Search code examples
javascriptjqueryhtmlcssjquery-cycle2

how to display both prev/next button when hover img in cycle2.js


I want to display both the prev/next button when hover image in cycle2.js.

This is the link for your reference http://jquery.malsup.com/cycle2/demo/prevnext.php

<div class="cycle-slideshow" 
data-cycle-fx=scrollHorz
data-cycle-timeout=0
>
<!-- prev/next links -->
<div class="cycle-prev"></div>
<div class="cycle-next"></div>
<img src="http://malsup.github.io/images/p1.jpg">
<img src="http://malsup.github.io/images/p2.jpg">
<img src="http://malsup.github.io/images/p3.jpg">
<img src="http://malsup.github.io/images/p4.jpg">
</div>

Solution

  • This should do it:

    $(function () {
        $(".cycle-prev, .cycle-next").css("opacity", "0");
    
        $(".cycle-slideshow").hover(function () {
            $(".cycle-prev, .cycle-next").css("opacity", ".7");
        }, function () {
            $(".cycle-prev, .cycle-next").css("opacity", "0");
        });
    });