dongzhuang2030 2014-05-30 13:44
浏览 20
已采纳

如何创建基于目录的滑块的两个实例?

Update: After much confusion it turns out that the issue was in my stylesheet. Both of the sliders were in fact loading, however, the positioning caused them to overlap, hiding the second (or any additional) sliders.

I've been attempting to create two instances of this jQuery slider that uses images from a specific directory. Folders are generated by a different script and contain 18 images each. It appears that only the first slider works.

You can view a live example of this issue here.

The jQuery is pretty straight-forward, however, please note that I'm still learning PHP, however I've been able to list folders within my main directory and create what would be the correct markup for multiple sliders.

<?php
$a = 0;
$b = 0;
$c = 0;

if ($handle = opendir('.')) {
$blacklist = array('.', '..', 'frames', 'carbon_fibre.png', 'panel.png', 'sort.php', 'squares.png', 'test.php', 'test.txt', '360logo.png', '.DS_Store', 'js');
while (false !== ($file = readdir($handle))) {
    if (!in_array($file, $blacklist)) {
        echo "<div id='". ++$a ."'>". ++$b ."</div>";
        echo "<br>";
        echo "<script>
$('#". ++$c ."').directorySlider({
animation: 'fade',
filebase: 'a',
directory: '".$file."/',
extension: 'jpg',
numslides: 18,
height: 200,
timeout: 100,
speed: 100
});

</script><br>";
    }
}
closedir($handle);
}

?>

The output of this script is:

<div id='1'>1</div><br><script>
$('#1').directorySlider({
animation: 'fade',
filebase: 'a',
directory: '20140529-1740/',
extension: 'jpg',
numslides: 18,
height: 200,
timeout: 100,
speed: 100
});

</script><br><div id='2'>2</div><br><script>
$('#2').directorySlider({
animation: 'fade',
filebase: 'a',
directory: '20140529-1751/',
extension: 'jpg',
numslides: 18,
height: 200,
timeout: 100,
speed: 100
});

</script>

The output seems to be correct, it correctly lists my directories in the scripts, but I still only see the first slider working. I should mention that these directories are generated automatically and are titled by the the date and time of creation.

Please let me know if you have any advice or insight as to why I'm experiencing this issue. I'm more than happy to provide more information. I really do appreciate your time.

  • 写回答

1条回答 默认 最新

  • doubi6669 2014-06-16 18:24
    关注

    I was checking your code and the website author, that confirm that you can have lot of instances of the plugin.

    I was going crazy because I'm getting same problem as you, but I finally found that you have is a CSS problem. The two sliders are showing in same place, one over another.

    Browser position the id 2 bottom to 1, but the own internal style that maybe apply the script are display one above the other...

    If you apply this style to your divs

    <div id='1' style="position:absolute;left:1px; top:1px;width:300px;">1</div>
    
    <div id='2' style="position:absolute;right:1px; top:1px;width:300px;">2</div>
    

    you will see that two sliders are there. I was check your own link example with this style and I saw twice. Cheers

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

报告相同问题?

悬赏问题

  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab