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

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思