JQuery Carousel - IF ELSE语句显示为第一个(“活动”)超链接图像


I have a JQuery carousel with four images stored in a file called carousel.php. I also have a gallery.php file where are the four images in a list as hyperlinks. When I click on them I get their "id"

<li><a href='carousel.php?id=1'><img src=1.jpg'></a></li>
<li><a href='carousel.php?id=2'><img src=2.jpg'></a></li>
<li><a href='carousel.php?id=3'><img src=3.jpg'></a></li>
<li><a href='carousel.php?id=4'><img src=4.jpg'></a></li>

at the gallery.php through $id=$_GET['id'] and then I create a javascript variable of this id called $imgvar.

var $imgvar = "<?php echo $id; ?>";

So, I want the carousel to display first the image which was clicked by the user and then continue the normal order. (e.g. if I click 3.jpg, the carousel starts displaying 3.jpg and then I click the "right navigation arrow" goes to 4.jpg or if I click the "left navigation arrow" goes to 2.jpg etc).

I guess I need a IF else statments to compare the id with each image and make "active" the one which was hyperlinked, but I can't find the right way. Anybody who might help?

Thanks for your time.

You could just simply use the scroll method to scroll to the item via index directly after initialization.

Take the number of the item from your GET parameter, and output the JavaScript code to call the scroll method with that number. (If you are passing numbers from 1 to x, you will have to decrement it by one, because scroll uses the zero-based item index.)