如何用PHP和JQuery制作一个小图库
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何用PHP和JQuery制作一个小图库相关的知识,希望对你有一定的参考价值。
This is the code to make a simple gallery really fast, with php, jquery and a dir full of pictures.
<? //--------------------------------------------- //Php Function to read the images in a dir function getJsArray($dir) { $out = ""; if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) if(in_array( substr(strrchr($file, '.'), 1) , array('gif','png','jpg') )) $out.= ($out?",":"")."'".$dir.$file."'"; closedir($dh); } else { die ("no dir"); } return $out; } ?> <html> <head> <title>Mini PHP-Jquery Gallery/Slideshow</title> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> //--------------------------------------------- var gallery_current_pos = 0; // gallery counter position var gallery_idname = "container"; // id of the gallery container var gallery_timer = 5000; // 5 seconds var gallery_ar = Array(<?=getJsArray("./minislides/")?>); function goGallery() { if (gallery_current_pos>gallery_ar.length - 1) gallery_current_pos =0; $('#'+gallery_idname).fadeTo("fast", 0 , function () { $('#'+gallery_idname).css("background-image","url(" + gallery_ar[gallery_current_pos] + ")"); $('#'+gallery_idname).fadeTo("slow", 1); gallery_current_pos++; }); if (gallery_ar.length>1) setTimeout( function () { goGallery(); }, gallery_timer); } //--------------------------------------------- </script> <style> #container {background-repeat:no-repeat;width:300px;height:200px;} </style> </head> <body onload="goGallery();"> <div id='container'> </div> </body> </html>
以上是关于如何用PHP和JQuery制作一个小图库的主要内容,如果未能解决你的问题,请参考以下文章