0

我正在寻找一些带有上一个/下一个按钮的画廊,我找到了它。我有代码:

var speed = 0;
$('#mask-gallery, #gallery li').width($('#slider').width());    
$('#gallery').width($('#slider').width() * $('#gallery li').length);
$('#mask-gallery, #gallery li').height($('#slider').height());
$('#gallery li:first').addClass('selected');

$('#btn-next, #gallery').click(function () {
 newsscoller(0);    
 return false;
});

$('#btn-prev').click(function () {
 newsscoller(1);    
 return false;
});

function newsscoller(prev) {
    var current_image = $('#gallery li.selected').length ? $('#gallery li.selected') : $('#gallery li:first');
    if (prev) {
        var next_image = (current_image.prev().length) ? current_image.prev() : $('#gallery li:last');
    } else {
        var next_image = (current_image.next().length) ? current_image.next() : $('#gallery li:first');
    }

    $('#gallery li').removeClass('selected');
    next_image.addClass('selected');
    $('#mask-gallery').scrollTo(next_image, 250);
}

http://jsfiddle.net/R27FS/

我有一个问题。任何人都知道它的脚本如何在最后一张幻灯片之后将用户重定向到定义的页面(location.href = '';)?

感谢您的回复!

4

1 回答 1

0

一种选择是将“下一个”链接设置为最后一张幻灯片上的实际位置。然后return true;click事件中如果href!="#"

演示

var speed = 0;
$('#mask-gallery, #gallery li').width($('#slider').width());
$('#gallery').width($('#slider').width() * $('#gallery li').length);
$('#mask-gallery, #gallery li').height($('#slider').height());
$('#gallery li:first').addClass('selected');

$('#btn-next, #gallery').click(function () {
    var href = $(this).attr("href");
    if (href != "#" && href != "") return true;
    newsscoller(0);
    return false;
});

$('#btn-prev').click(function () {
    newsscoller(1);
    return false;
});

function newsscoller(prev) {
    var current_image = $('#gallery li.selected').length ? $('#gallery li.selected') : $('#gallery li:first');
    var next_image;
    $("#btn-next").attr("href", "#");
    if (prev) {
        next_image = (current_image.prev().length) ? current_image.prev() : $('#gallery li:last');
    } else {
        if (current_image.next().length) {
            next_image = current_image.next();
        }
        if (!next_image.next().length) {
            $("#btn-next").attr("href", "http://www.google.com");
            //'target' required for it to work in jsFiddle b/c of 
            //iframe, remove in your code.
            $("#btn-next").attr("target", "_blank");
        }
    }

    $('#gallery li').removeClass('selected');
    next_image.addClass('selected');
    $('#mask-gallery').scrollTo(next_image, 250);
}
于 2013-03-07T20:43:11.710 回答