drazvzi741287 2011-11-26 05:59
浏览 59
已采纳

PHP jquery轮播位置

I'm using php pagination to load different data from a text file. I am using a jquery carousel http://tympanus.net/Development/Elastislide/index4.html that is featured on each page created from the pagination. What I would like to do is, depending on which page you are on, the carousel will load in a different position. To get this working, I'm thinking I would need to change the jquery which loads on each created page?

<script type="text/javascript">
$('#carousel').elastislide({
            imageW      : 110,
            margin      : 20,
            border      : 4,
            easing      : 'easeInBack',
            current     : 12
        });
</script> 

So if the pagination is on the page.php?p=12, the carousel would be on thumbnail 12? Example html:

<div id="carousel" class="es-carousel-wrapper">
    <div class="es-carousel">
        <ul>
            <li><a href="page.php?p=1"><img src="images/img1.jpg" width="100" height="130" alt="image01" /></a></li>
            <li><a href="page.php?p=2"><img src="images/img2.jpg" width="100" height="130" alt="image02" /></a></li>
        </ul>
    </div>
</div>

the pagination i'm using:

<?php
    $data=file("students.txt");
    $pages=0;
    foreach($data as $temp){
        $x=explode("|",$temp);
        if($x[0]>0){
            $pages=$pages+1;
        }
    }
    if($_GET['p']){
        $page=$_GET['p'];
    }
    if($_GET['i']){
        $index=$_GET['i'];
    }  
    if($index == "p"){
        $page=$page-1;
    }
    if($index == "n"){
        $page=$page+1;
    }
    if($page < 1){
        $page=1;
    }
    if($page > $pages){
        $page=$pages;
    } 
    $line=$data[$page-1];
    $fields=explode("|",$line);  
?>

I'm new to PHP and I really don't have a clue on how to put this together...

Does anyone have any ideas how to make this work? :(

  • 写回答

3条回答 默认 最新

  • drnf09037160 2011-11-26 06:07
    关注

    Have that PHP be the first thing on the page, then in the carousel script initiation block use:

    current : <?=$page?> 
    

    or, if you're unsure whether short tags are enabled:

    current : <?php echo $page;?> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面