jQuery FlexSlider-链接到特定图像

jQuery FlexSlider-链接到特定图像,jquery,Jquery,在另一篇帖子()中,用户LJ902回答了如何链接到Flexslider中的特定图像。它工作得很好,但前提是链接与图像位于同一页面 我想要的是:在头版,有一堆图像微缩。。当你点击其中一个,你会看到一个新的页面,所有的图像都显示在Flexslider中,选中的是用户在首页上选择的图像 这是链接和图像的代码。请注意链接中的“rel”: <a rel="0" class="slide_thumb" href="#">slide link 1</a> <a rel="1" c

在另一篇帖子()中,用户LJ902回答了如何链接到Flexslider中的特定图像。它工作得很好,但前提是链接与图像位于同一页面

我想要的是:在头版,有一堆图像微缩。。当你点击其中一个,你会看到一个新的页面,所有的图像都显示在Flexslider中,选中的是用户在首页上选择的图像

这是链接和图像的代码。请注意链接中的“rel”:

<a rel="0" class="slide_thumb" href="#">slide link 1</a>
<a rel="1" class="slide_thumb" href="#">slide link 2</a>
<a rel="2" class="slide_thumb" href="#">slide link 3</a>

<div class="flexslider">
<ul class="slides">
    <li>
        <img src="demo-stuff/inacup_samoa.jpg" />
        <p class="flex-caption">Captions and cupcakes. Winning combination.</p>
    </li>
    <li>
        <a href="http://flex.madebymufffin.com"><img src="demo-stuff/inacup_pumpkin.jpg"       /></a>
        <p class="flex-caption">This image is wrapped in a link!</p>
    </li>
    <li>
        <img src="demo-stuff/inacup_donut.jpg" />
    </li>
    <li>
        <img src="demo-stuff/inacup_vanilla.jpg" />
    </li>
    <li>
        <img src="demo-stuff/inacup_vanilla.jpg" />
    </li>
  </ul>
 </div> 

  • 标题和纸杯蛋糕。赢的组合

  • 此图像包装在一个链接中

这是剧本:

<script type="text/javascript" charset="utf-8">
jQuery(document).ready(function($) {

$('.flexslider').flexslider({
    animation: "slide",
    slideshow: false,
    animationLoop: false,
    directionNav: true,
    slideToStart: 0,
    start: function(slider) {
        $('a.slide_thumb').click(function() {
            $('.flexslider').show();
            var slideTo = $(this).attr("rel")//Grab rel value from link;
            var slideToInt = parseInt(slideTo)//Make sure that this value is an integer;
            if (slider.currentSlide != slideToInt) {
                slider.flexAnimate(slideToInt)//move the slider to the correct slide  (Unless the slider is also already showing the slide we want);
            }
        });
    }

});

});

jQuery(文档).ready(函数($){
$('.flexslider').flexslider({
动画:“幻灯片”,
幻灯片放映:错误,
animationLoop:false,
方向导航:对,
幻灯片开始:0,
开始:功能(滑块){
$('a.slide_thumb')。单击(函数(){
$('.flexslider').show();
var slideTo=$(this).attr(“rel”)//从链接获取rel值;
var slideToInt=parseInt(slideTo)//确保此值为整数;
如果(slider.currentSlide!=slideToInt){
slider.flexAnimate(slideToInt)//将滑块移动到正确的幻灯片上(除非滑块已经显示了我们想要的幻灯片);
}
});
}
});
});

正如我所说的,如果链接与Flexslider位于同一页面中,上述功能就可以正常工作

但我希望该链接出现在头版,然后该链接必须链接到另一个页面,如:

<a rel="0" class="slide_thumb" href="mySubpage">slide link 1</a>

但是上面的操作失败了,因为我只看到了子页面,没有显示正确的图像(它总是显示第一个图像)

如果有人能告诉我如何解决这个问题,我将非常感激:)

谢谢


V.

您需要做的是在两个页面之间传递一个参数:

<a rel="0" class="slide_thumb" href="yourpage?img=0">slide link 1</a>
<a rel="1" class="slide_thumb" href="yourpage?img=1">slide link 2</a>

我非常感谢你的回答!当然,传递一个参数是有意义的。但是我在实现这个(解析错误:语法错误,意外的“')时确实有点麻烦,应该是“&”或T_变量)。@VeronicaE。这听起来像是一个PHP错误,我的代码中没有PHP,全部是js。我确实有点麻烦。我拥有的页面有:IndexMain.php(首页)、IndexSub.php(所有图像所在的子页面)和functions.php(保存函数的地方)。我在函数页中得到了这个错误:(解析错误:语法错误,意外'),应为'&'或T_变量)。index.php的内容:echo“”;Functions.php:echo“var$\u GET=getQueryParams(document.location.search);var startAt=($\u GET['img'])?$\u GET['img']:0);”@维罗尼卡。您不必将jsCode放在PHP中,那里没有echo,只需使用一个块即可。你有没有机会把代码粘贴到某个地方,让我看看?你真是太好了!如果我不能让它工作,我会把它放进去,然后马上回来。我真的很感谢您的时间和回复:)
function getQueryParams(qs) {
    qs = qs.split("+").join(" ");
    var params = {},
        tokens,
        re = /[?&]?([^=]+)=([^&]*)/g;

    while (tokens = re.exec(qs)) {
        params[decodeURIComponent(tokens[1])]
            = decodeURIComponent(tokens[2]);
    }

    return params;
}

// assoziative object the key is the get parameter name
var $_GET = getQueryParams(document.location.search);

// now you only have to modify the line:
// var slideTo = $(this).attr("rel")//Grab rel value from link;
// like this:
var slideTo = (($_GET['img']) ? $_GET['img'] : 0);
// if img parameter is set, you slide to it, fallback is the first one.