Cycle2 Plugin Ẩn / Hiện các nút jQuery (Cycle2 Plugin Hide/Show buttons jQuery)


問題描述

Cycle2 Plugin Ẩn / Hiện các nút jQuery (Cycle2 Plugin Hide/Show buttons jQuery)

I have used the jQuery cycle2 plugin on a blog website. What i want the slideshow to do is when there is more than 1 image displayed, the controls will show‑at the moment they are hidden through css.

The plugin is used by declaring it in my header (here is the link to the js file: http://malsup.github.com/jquery.cycle2.js

And then my css contains a class for the container of the slideshow, class for the container for the buttons and a class each for prev and next buttons:

css:

.cycle‑slideshow {
    height:400px;
    z‑index:0;
}

.cycle‑slideshow  img{
    width:100%;
    height:100%;
    z‑index:3;
}

.center {
 display:none;  
}

.center a{
    z‑index:4;
    position:absolute;
    margin‑top:‑48px;
}

.center a:hover {
    display:block;
}


.center a#prev, .center a#next{
    position:relative;
    width:4%;
    height:60px;
    width:60px;
    margin‑top:‑60px;
    font‑size:40px;
    text‑align:center;  
    color:#FFF;

}

.center a#next{
    float:right;
    background:url(images/next.png) center ‑2px no‑repeat;
}

.center a#prev {
        float:left;
    background:url(images/prev.png) center ‑2px no‑repeat;
}

My html code is actually embedded within a wordpress function but the html format goes along the lines of:

<div class="cycle‑slideshow"
    data‑cycle‑fx="scrollHorz"
    data‑cycle‑pause‑on‑hover="true"
    data‑cycle‑speed="200"
    data‑cycle‑next="#next"
    data‑cycle‑prev="#prev"
    data‑cycle‑swipe="true">

    //does stuff here
    </div>
    <div class="center">
        <a href="javascript:void(0);" id="prev">&nbsp;</a> 
        <a href="javascript:void(0);" id="next">&nbsp;</a>
    </div>

The following code i was told to do (the first three lines) but this still doesn't seem to work. 

$(document).ready(function () {   
            $('.cycle‑slideshow').on( 'cycle‑initialized', function( e, opts ) {
            if ( opts.slideCount > 1 ) {
                $(".center").css("display", "block");
            }
    });
});

Im not the best with jQuery so can anyone help or give me any guidance please?


參考解法

方法 1:

In this case you are going to want to initialize the slideshow via code AFTER you add the event handler.  Remove the cycle‑slideshow  class so it doesn't auto initialize and then you can do this:

Demo:  http://jsfiddle.net/lucuma/zyhrK/1/

$('.slideshow').on('cycle‑initialized', function (e, opts) {
    if (opts.slideCount > 1) {
        $(".center").css({
            "display": "block"
        });
    }
});

$('.slideshow').cycle();

(by Shimsham84lucuma)

參考文件

  1. Cycle2 Plugin Hide/Show buttons jQuery (CC BY‑SA 3.0/4.0)

#controls #jquery-cycle #show-hide






相關問題

如何在不阻塞的情況下用大量信息填充列表視圖? (How to populate listview with a lot of information without blocking?)

查看項目是否在列錶框控件中的最有效方法 (Most efficient way to see if an item is or is not in a listbox control)

tcng - 匹配“if”語句中的端口範圍 (tcng - match port range in "if" statement)

將圖像加載到面板 (Load image to panel)

Cycle2 Plugin Ẩn / Hiện các nút jQuery (Cycle2 Plugin Hide/Show buttons jQuery)

如何使用 Windows 資源管理器顯示項目和詳細信息展開/折疊 (How to Display Items and Details with Windows Explorer Expand/Collapse)

ASP.NET 2.0 JQuery AJAX 登錄 (ASP.NET 2.0 JQuery AJAX Login)

單步執行控件看不到第二個下拉菜單 (Step through controls fail to see second dropdown)

用戶控件、服務器控件和自定義控件之間有什麼區別? (What are the differences between User Controls, Server Controls & Custom Controls?)

GroupBox 控件中的圓角 (Rounded corners in GroupBox control)

在 .NET 中編寫大型多步驟表單的最有效方法是什麼? (Most efficient way to code a large multi-step form in .NET?)

如何從 ASP .NET MVC 中的動態生成控件中獲取數據? (How can I get data from dynamic generated controls in ASP .NET MVC?)







留言討論