BxSlider - 获取第一张和最后一张幻灯片 [英] BxSlider - get first and last slide

查看:24
本文介绍了BxSlider - 获取第一张和最后一张幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm using BxSlider to make a slider. I have set it to display 3 slides at the time. Works fine. Now I'm trying to get first and last slide by calculating current and total number of slides. Currently I have a total of 10 slides - and that number can vary - (to be displayed 3 at the time) and so my function doesn't work. It works if I have six or nine slides obviously.

The reason I'm interested in getting the first and last slide is because I'm going to hide the last and right link respectively. See my fiddle here. My function is this:

function LastSlide() {
            var total = slider.getSlideCount();
            var current = slider.getCurrentSlide() + 1;
            var lastslide = total / current;
            if (current == lastslide) { // Last slide
               //run stuff
            }
        }

- but when lastslide gets decimals, bad things start to happen. Anyone got an idea how to solve this? See first link for bxSlider documentation.

解决方案

I'm not sure why exactly you are doing the LastSlide thing - I think you can just remove that variable from the function because the division isn't the correct function you need.

Also your fiddle never shows the "Go Left" because it only shows up when current equals lastslide which is never happening.

Here is a very simple fiddle to make the functionality work: http://jsfiddle.net/CKxg9/14/

Also the names are quite confusing. I mean the CURRENT slide is counting 1 (3 DIVS), 2 (6 DIVS) and the total slides are 10 (in my case I used 14) which should be the DIVS not the slides.. So if you really want to work with the lastslide thing you could use:

var total = Math.ceil(slider.getSlideCount()/3);

This means if u have 10 DIVS and you want to slide 3 at once you will have 4 slides (1-3,4-6,7-9,10) Now you could use

if (current == total) {
    $('#right').hide();
} else {
    $('#right').show();
}

Here is a fiddle using the 2nd method: http://jsfiddle.net/CKxg9/15/ You can of course remove the lastslide because this isn't doing anything..

Tho you still have to initialize the $('#left').show() somewhere when current > 1...

This should help you to solve your issue - I hope..

这篇关于BxSlider - 获取第一张和最后一张幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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