简体   繁体   English

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

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

So I've tried searching here, and I've found similar problems, but not like mine actually, that I could use.. So the thing is I'm using jquery cycle plugin, and all is working great. 因此,我尝试在这里搜索,但发现了类似的问题,但实际上我不喜欢我可以使用的问题。因此,问题是我正在使用jquery循环插件,并且一切正常。 So this is jquery I am using on page, let's say page.html 这就是我在页面上使用的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;
    });
});

Your guess is that I'm using navigation like this to go through that: 您的猜测是,我正在使用像这样的导航来进行以下操作:

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

and finaly div structure would be 最后的div结构将是

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

And that workds fine. 那很好。 Now my question is, can I target, let's say, div two from index.html? 现在我的问题是,我可以定位index.html的div吗? Page is not php, my idea was to create a href from index to page.html#goto2 and somehow use that, but since its not php I do'nt know how would I do that... If someone knows a trick I would be grateful. 页面不是php,我的想法是创建一个从索引到page.html#goto2的href,并以某种方式使用它,但是由于它不是php,所以我不知道该怎么做...如果有人知道一个把戏,我会非常感激。 Thanks. 谢谢。

Send querystring as ?tab=1 , tab=2 , tab=3 according to the tab you want 根据您想要的选项卡将查询字符串发送为?tab=1tab=2tab=3

Now set the tab according to QueryString value change tabs. 现在根据QueryString值更改选项卡设置选项卡。 For simplicity we added id's to the anchor inside list and attach href to each anchor dynamically. 为简单起见,我们将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");
            }
        });

     }

Now our jquery cycle was adding class currentactive1_on_tab name automatically, so we used it for mapping the thumbnails with the slides. 现在,我们的jquery周期是自动添加类currentactive1_on_tab name ,因此我们将其用于映射缩略图和幻灯片。 Also, we were changing the css accordingly in our activate and deactivate functions - in order to work like the jquery cycle. 另外,我们在activatedeactivate功能中相应地更改了css,以便像jquery循环那样工作。

Let me know if you have any questions. 如果您有任何疑问,请告诉我。

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

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