Вопрос

EDIT: This is not a problem with the jQuery creating the appropriate markup from SharePoint Announcement List to use jCarouselLite. It seems to be a problem within jCarouselLite. I have done another jsfiddle with just the appropriate markup, not the jQuery/javascript conversion code, and the problem still occurs.

You can see the problem at http://jsfiddle.net/ayatollah/6RKNx/

Again it is only a problem with 1 or 2 list items. 3+ works fine. Should I be changing the markup, our jCarouselLite calling code to fix this?

Bounty will be offered as soon as it's available!

ORIGINAL===============================================================================

I have an Announcement List in a Sharepoint site that I want to convert to a jCarousel. The Announcement List is rendered as a table so I have put together some jQuery code to convert it to the required ul structure.

The jQuery seems to be doing its job but the jCarousel gives some weird behaviour. The first announcement displays as it should, then the second announcement scrolls in as it should. However, for each scroll after this it flashes up the first announcement, then scrolls in the second. When it should just scroll in the first again.

I had it working correctly but it was displaying blank announcements, so I introduced some code to filter out the blank announcements. Here is a jsfiddle to show you the problem.

http://jsfiddle.net/RzeEX/2/

The only change I made from the previous code was to add the extra boolean value:

&& $(listitem).text() != "\xa0"

Seen at: http://jsfiddle.net/RzeEX/3/

However, in the above fiddle the code works exactly as the previous one, but on my server it displays an extra blank announcement. Don't know why I can't replicate it here.

Anyway, anyone have any ideas?

EDIT: Actually just testing it with more than 2 announcements and it seems to work. See http://jsfiddle.net/RzeEX/4/

It is now working as expected, but have 2 announcements and it is still broke, have 1 announcement and nothing shows! It must be something to do with the jQuery as I would believe the jCarouselLite plugin to work.

See http://jsfiddle.net/RzeEX/5/ for the single announcement.

Это было полезно?

Решение

Since it is my understanding that you might have a dynamic list of elements, you can do something like this:

$('.viewport').jCarouselLite({
    auto:1000,
    speed:1000,
    visible: $('#announcementList li').length
});

That way it won't matter if you have 1, 2 or 100 elements. It will always work as it should.

Here's the jsfiddle: http://jsfiddle.net/XS87c/

Другие советы

I think by setting visible:2 may give the desire result.

$('.viewport').jCarouselLite({
                    auto:5000,
                    speed:1000,
                    visible:2
              });   

let me know if it does not work.

how many do you want to be visible? what behaviour do you want if there is < # visible. I ran into this exact problem, and solved it by not applying the carosel if there was < # visible in the list.

something like this should do the trick:

if ((document.getElementById('viewport') != null) && $('#announcementList').find('li').length >= 3 ) {
    $('.viewport').jCarouselLite({
        auto: 5000,
        speed: 1000
    });
}

Complementing the solution of Irfan, you can do:

if(document.getElementById('viewport') != null) {
     var options = {auto:5000,speed:1000}; 
     //Here we count the number of items and set it for a better display for 2 and 1 item
     if($('#viewport a').length <= 2) {
         options.visible = $('#viewport a').length;
     } 
     $('.viewport').jCarouselLite(options);     
}

So if you have on or two elements you will see just one or two. But if you have more than two elements you will see just three elements.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top