jQuery循环插件,嵌套幻灯片,“之后"选项或测试第一张和最后一张图片 [英] jquery cycle plugin, nested slideshow, 'after' option or testing for first and last image

查看:130
本文介绍了jQuery循环插件,嵌套幻灯片,“之后"选项或测试第一张和最后一张图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在嵌套的幻灯片中,我具有上一个"和下一个"控件.如果您在第一张幻灯片上,我希望能够降低css的不透明性,如果在最后一张幻灯片上,则可以降低下一页"的css不透明度.

In my nested slideshows I have 'prev' and 'next' controls. I would like to be able to reduce the css opacity of 'prev' if you are on the first slide and 'next' if you are on the last slide.

'after:onAfter'选项就足够了,但是当放置在我的嵌套幻灯片显示控件的代码中时,它似乎不起作用.

The 'after: onAfter' option would have been sufficient but it didn't appear to work when placed in my code for the nested slideshow controls.

是否有办法在嵌套幻灯片中正确实现之后",或者测试嵌套幻灯片中的第一张和最后一张图像?谢谢

Is there a way to implement 'after' correctly in a nested slideshow, or alternatively test for first and last images in the nested slideshow? Thankyou

这是我的代码.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript" src="http://malsup.github.com/jquery.cycle.all.js"></script>
<script type="text/javascript">
$(document).ready(function() {                     
// init and stop the inner slideshows
var inners = $('.inner-slideshow').cycle().cycle('stop');
var slideshow = $('#slideshow').cycle({
    fx:     'fade',
    speed:  'fast',
    timeout: 0,
    pager:  '#nav',
    pagerAnchorBuilder: function(idx, slide) {
        // return sel string for existing anchor
        return '#nav li:eq(' + (idx) + ') a';
    },
    before: function() {
        // stop all inner slideshows
        inners.cycle('stop');
        // start the new slide's slideshow
        $(this).cycle({
            fx: 'scrollHorz',
            speed:  'fast',
            timeout: 0,
            prev: '#prev',
            next: '#next',
            nowrap:  1
        });
    }
});
});
</script>
<title>dev</title>
</head>
<body>
<ul id="nav">
<li><a href="#">Top Slidehsow 1</a></li>
<li><a href="#">Top Slidehsow 2</a></li>
</ul>
<div id="controls">
    <a id="prev" href="#">&lt; Prev</a>
    <a id="next" href="#">Next &gt;</a>
</div>
<div id="slideshow">
    <div class="inner-slideshow">
        <img src="http://cloud.github.com/downloads/malsup/cycle/beach1.jpg" width="200" height="200">
        <img src="http://cloud.github.com/downloads/malsup/cycle/beach2.jpg" width="200" height="200">
    </div>
    <div class="inner-slideshow">
        <img src="http://cloud.github.com/downloads/malsup/cycle/beach4.jpg" width="200" height="200">
        <img src="http://cloud.github.com/downloads/malsup/cycle/beach5.jpg" width="200" height="200">
        <img src="http://cloud.github.com/downloads/malsup/cycle/beach6.jpg" width="200" height="200">
    </div>
</div>
</body>
</html>

推荐答案

我认为这就是您想要的(编辑您的示例): http://jsfiddle.net/m8AFG/18/

I think this is what you wanted (edited your example): http://jsfiddle.net/m8AFG/18/

$(document).ready(function() {
    // init and stop the inner slideshows
    var inners = $('.inner-slideshow').cycle().cycle('stop');
    var slideshow = $('#slideshow').cycle({
        fx: 'fade',
        speed: 'fast',
        timeout: 0,
        pager: '#nav',
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
            return '#nav li:eq(' + (idx) + ') a';
        },
        before: function() {
            // stop all inner slideshows
            inners.cycle('stop');
            // start the new slide's slideshow
            $(this).cycle({
                fx: 'scrollHorz',
                speed: 'fast',
                timeout: 0,
                prev: '#prev',
                next: '#next',
                nowrap: 1,
                after: function() {
                    $('#prev').removeClass('opac');
                    $('#next').removeClass('opac');
                    var countImg = $(this).siblings().size();
                    if ($(this).index() == 0) $('#prev').addClass('opac');
                    if ($(this).index() == countImg) $('#next').addClass('opac');
                }
            });
        }
    });
});

添加了CSS的不透明度以及jquery和cycle脚本链接,并且效果很好

added css opacity and the jquery and cycle script link, and it works fine

迈克尔,问候

这篇关于jQuery循环插件,嵌套幻灯片,“之后"选项或测试第一张和最后一张图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆