繁体   English   中英

jQuery周期-您能否定位其他页面上的某些“幻灯片”?

[英]jquery cycle - can you target certain “slide” from other page?

因此,我尝试在这里搜索,但发现了类似的问题,但实际上我不喜欢我可以使用的问题。因此,问题是我正在使用jquery循环插件,并且一切正常。 这就是我在页面上使用的jQuery,比方说page.html

$(function() {
    $('#rotation').cycle({ 
        fx:'scrollRight',
        timeout: 0,
        speed: 500,
        startingSlide: 0
    });

    $('#goto1').click(function() { 
        $('#rotation').cycle(0);

        return false;
    });

    $('#goto2').click(function() { 
        $('#rotation').cycle(1); 

        return false;
    });
});

您的猜测是,我正在使用像这样的导航来进行以下操作:

<li><a href="#" id="goto1">Link1</a></li>
<li><a href="#" id="goto2">Link2</a></li>

最后的div结构将是

<div id="rotation">
    <div> Content of first cycle </div>
    <div> Content of second cycle </div>
</div>

那很好。 现在我的问题是,我可以定位index.html的div吗? 页面不是php,我的想法是创建一个从索引到page.html#goto2的href,并以某种方式使用它,但是由于它不是php,所以我不知道该怎么做...如果有人知道一个把戏,我会非常感激。 谢谢。

根据您想要的选项卡将查询字符串发送为?tab=1tab=2tab=3

现在根据QueryString值更改选项卡设置选项卡。 为简单起见,我们将id添加到列表中的锚点,并将href动态附加到每个锚点。

    // Run this on document ready.
    var listItemsofThumbnail = $("ul.sidebarTabset li");

    listItemsofThumbnail.each(function (idx) {
        var licount = idx + 1;
        $(this).addClass("currentactive1_s" + licount)
        var linkurl = $(this).find("a").attr("href");
         $(this).find("a").attr("href", linkurl + "?tab=" + licount);
     });


    var currenturl = window.location.href;
    var QuerystringValue = getParameterByName("tab");

    switchImages(QuerystringValue);

    // document ready end.

    function switchImages(tab) {
       if (tab == null || tab == undefined || tab == 0) tab = 1; // catch any bad data
           DeactivateAllTab();
           ActivateTab(tab - 1);
       }


     // Dsiplays the li 
    function ActivateTab(i) {
         if (!($("#slider1 li#currentactive1_s" + i).hasClass("currentactive1_on"))) {
              $("#slider1 li#currentactive1_s" + i).addClass("currentactive1_on");
              $("#slider1 li#currentactive1_s" + i).css({ "float": "left", "position": "relative", "opacity": 1, "zIndex": 2, "display": "list-item" });
          }
         var thumbnailindex = i + 1;
         if (!($(".sidebarTabset li.currentactive1_s" + thumbnailindex).hasClass("active"))) {
            $(".sidebarTabset li.currentactive1_s" + thumbnailindex).addClass("active");
         }

     }

     // Hides the li
     function DeactivateAllTab() {
        $("#slider1 > li").each(function () { 
          $(this).removeClass("currentactive1_on");
          $(this).css({ "float": "none", "position": "absolute", "opacity": 0, "zIndex": 0 });
});
        $(".sidebarTabset li").each(function () {
           if ($(this).hasClass("active")) {
               $(this).removeClass("active");
            }
        });

     }

现在,我们的jquery周期是自动添加类currentactive1_on_tab name ,因此我们将其用于映射缩略图和幻灯片。 另外,我们在activatedeactivate功能中相应地更改了css,以便像jquery循环那样工作。

如果您有任何疑问,请告诉我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM