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 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
  • ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
  • ¥20 C#上传XML格式数据
  • ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下
  • ¥100 单片机hardfaulr
  • ¥20 手机截图相片分辨率降低一半
  • ¥50 求一段sql语句,遇到小难题了,可以50米解决
  • ¥15 速求,对多种商品的购买力优化问题(用遗传算法、枚举法、粒子群算法、模拟退火算法等方法求解)
  • ¥100 速求!商品购买力最优化问题(用遗传算法求解,给出python代码)
  • ¥15 虚拟机检测,可以是封装好的DLL,可付费