jQuery jCarousel - 外部控件突出显示(换行:圆形)+随机幻灯片

发布于 2024-09-30 13:12:40 字数 658 浏览 4 评论 0原文

我在实现 jQuery 的 jCarousel 插件时遇到了一些问题。 我正在使用的代码可在 http://projects.klavina.com/stackoverflow /index-slider.html

问题1: 我需要突出显示滑块 #1 上的活动外部控件。我在 http://heidzir.com/blog/?p=21 找到了解决方案,但正如评论中已经指出的那样 - 当滑块进入第二个循环时,它会停止工作。

问题2: 我需要在页面加载时随机化滑块#2(引号)上的幻灯片。我找到了一种随机化 li 的方法(随机化 div 元素序列jQuery),但滑块停止工作并仅滑动首先加载的报价。

任何帮助将不胜感激。谢谢你!

I've been having some problems with implementing the jCarousel plugin for jQuery.
The code I'm using is available at http://projects.klavina.com/stackoverflow/index-slider.html

Problem 1:
I need to highlight the active external control on slider #1. I found a solution at http://heidzir.com/blog/?p=21, but as already stated in the comments there - this stops working when the slider goes in the 2nd loop.

Problem 2:
I need to randomize the slides on slider #2 (quotes) on page load. I found a way to randomize the li's (Randomize a sequence of div elements with jQuery), but the slider stops working and slides only the quote that was loaded first.

Any help would be much appreciated. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

煞人兵器 2024-10-07 13:12:44

将 teasersize 设置为您拥有的列表项的数量

var teasersize = 4; // if you have 4 list items

set the teasersize to the number of list items you have

var teasersize = 4; // if you have 4 list items
一萌ing 2024-10-07 13:12:43

我遇到了问题#1,并找到了一个我想分享的解决方案。循环 jcarousels 的问题在于,“liindex”在遍历所有可用列表元素后不会从 1 开始计数,而是继续向上计数(如果您添加一个alert('liindex'),您会注意到这一点) 因此,如果您在

圆形自动轮播中有 3 个列表元素,那么一旦您完成第一次滚动并从第 1 项开始,jcarousel 就会在第 4 项而不是第 1 项处看到它

。关于这个),使用总项目和当前项目的模来计算 liindex,

            var totalitems = 3; // number of total items in your carousel, you can probably detect it with jquery and replace this 

            function mycarousel_initCallback(carousel) {
                    jQuery('#external ul li a').bind('click', function() {
                            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
                            return false;
                    });
                    carousel.clip.hover(function() {
                            carousel.stopAuto();
                    }, function() {
                            carousel.startAuto();
                    });
            };
            function highlight(carousel,objectli,liindex,listate){
                    actindex = teasersize - (liindex % teasersize); // calculate which item this corresponds to after first scroll
                    jQuery('#external a').removeAttr("class","active");
                    jQuery('#external a#link'+ actindex).attr("class","active");
            };
            function removehighlight(carousel,objectli,liindex,listate){
                    actindex = teasersize - (liindex % teasersize);
                    jQuery('#external a#link'+ actindex).removeAttr("class","active");
            };
            jQuery(document).ready(function() {
                    jQuery("#mycarousel").jcarousel({
                            initCallback: mycarousel_initCallback,
                            wrap: 'circular',
                            scroll: 1,
                            size: totalitems, // previously set in var
                            auto: 7,
                            itemVisibleInCallback:  highlight,
                            itemVisibleOutCallback: removehighlight,
                            buttonNextHTML: null,
                            buttonPrevHTML: null
                    });
            });

这就是基于 js 的外部导航应该是什么样子的:

            <ul id="external">
                <li><a href="#carouselitem1" id="link1">1</a></li>
                <li><a href="#carouselitem2" id="link2">2</a></li>
                <li><a href="#carouselitem3" id="link3">3</a></li>              </ul>

I had problem #1 and found a solution which I'd like to share. The problem with circular jcarousels is that the "liindex" doesn't start over with counting from 1 after it ran through all available list elements, but rather continues counting upwards (as you'll notice if you add an alert('liindex') inside the highlight function.

So if you have 3 list elements in a circular auto carousel, once you finish scrolling through the first time and start over with item 1, jcarousel sees it at the 4th item, not the 1st.

Here's my solution (based on this), calculating the liindex with the modular of the total items and the current item.

            var totalitems = 3; // number of total items in your carousel, you can probably detect it with jquery and replace this 

            function mycarousel_initCallback(carousel) {
                    jQuery('#external ul li a').bind('click', function() {
                            carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
                            return false;
                    });
                    carousel.clip.hover(function() {
                            carousel.stopAuto();
                    }, function() {
                            carousel.startAuto();
                    });
            };
            function highlight(carousel,objectli,liindex,listate){
                    actindex = teasersize - (liindex % teasersize); // calculate which item this corresponds to after first scroll
                    jQuery('#external a').removeAttr("class","active");
                    jQuery('#external a#link'+ actindex).attr("class","active");
            };
            function removehighlight(carousel,objectli,liindex,listate){
                    actindex = teasersize - (liindex % teasersize);
                    jQuery('#external a#link'+ actindex).removeAttr("class","active");
            };
            jQuery(document).ready(function() {
                    jQuery("#mycarousel").jcarousel({
                            initCallback: mycarousel_initCallback,
                            wrap: 'circular',
                            scroll: 1,
                            size: totalitems, // previously set in var
                            auto: 7,
                            itemVisibleInCallback:  highlight,
                            itemVisibleOutCallback: removehighlight,
                            buttonNextHTML: null,
                            buttonPrevHTML: null
                    });
            });

And this is what your external navigation should look like based on the js:

            <ul id="external">
                <li><a href="#carouselitem1" id="link1">1</a></li>
                <li><a href="#carouselitem2" id="link2">2</a></li>
                <li><a href="#carouselitem3" id="link3">3</a></li>              </ul>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文