dstnlhhv791576 2014-02-24 20:43
浏览 59
已采纳

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.

  • 写回答

1条回答 默认 最新

  • douyou8266 2014-02-26 13:35
    关注

    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.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题