插件87:幻灯片显示

本文介绍了一个PHP幻灯片展示插件,该插件能够从Flickr账户获取图片流并生成JavaScript代码来实现图片的幻灯片效果。插件需要Flickr账户名作为输入,并能处理图片的淡入淡出效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?php // Plug-in 87: Slide Show

// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link

$account = 'robinfnixon';
$result  = PIPHP_FetchFlickrStream($account);

if (!$result[0]) echo "No images returned";
else
{
   $style = "'position:absolute; top:10px; left:10px'";
   echo "<img id='PIPHP_SS1' style=$style>";
   echo "<img id='PIPHP_SS2' style=$style>";
   echo PIPHP_SlideShow($result[1]);
}

function PIPHP_SlideShow($images)
{
   // Plug-in 87: Slide Show
   //
   // This plug-in takes an array of URLs containing images
   // and returns the JavaScript required to display them in a
   // slideshow. It requires this argument:
   //
   //    $images: An array of image URLs

   $count = count($images);
   $out   = "<script>images = new Array($count);\n";

   for ($j=0 ; $j < $count ; ++$j)
   {
      $out .= "images[$j] = new Image();";
      $out .= "images[$j].src = '$images[$j]'\n";
   }

   $out .= <<<_END
counter = 0
step    = 4
fade    = 100
delay   = 0
pause   = 250
startup = pause

load('PIPHP_SS1', images[0]);
load('PIPHP_SS2', images[0]);
setInterval('process()', 20);

function process()
{
   if (startup-- > 0) return;

   if (fade == 100)
   {
      if (delay < pause)
      {
         if (delay == 0)
         {
            fade = 0;
            load('PIPHP_SS1', images[counter]);
            opacity('PIPHP_SS1', 100);
            ++counter;

            if (counter == $count) counter = 0;

            load('PIPHP_SS2', images[counter]);
            opacity('PIPHP_SS2', 0);
         }
         ++delay;
      }
      else delay = 0;
   }
   else
   {
      fade += step;
      opacity('PIPHP_SS1', 100 - fade);
      opacity('PIPHP_SS2', fade);
   }
}

function opacity(id, deg)
{
    var object          = $(id).style;
    object.opacity      = (deg/100);
    object.MozOpacity   = (deg/100);
    object.KhtmlOpacity = (deg/100);
    object.filter       = "alpha(opacity = " + deg + ")";
}

function load(id, img)
{
   $(id).src = img.src;
}

function $(id)
{
   return document.getElementById(id)
}

</script>
_END;

   return $out;
}

// The plug-in below is there to ensure it is available
// to the example code at the top of this file, which relies
// on it to build an array of image URLs

function PIPHP_FetchFlickrStream($account)
{
   // Plug-in 74: Fetch Flickr Stream
   //
   // This plug-in fetches a steam of photo URLs from a Flickr
   // account. Upon success it returns a two element array,
   // the first of which is the number of photos returned and
   // the second is an array containing URLs to each photo. On
   // failure it returns a single element array with the value
   // FALSE. It requires the following argument:
   //
   //    $account A fickr account name

   $url  = 'http://flickr.com/photos';
   $page = @file_get_contents("$url/$account/");
   if (!$page) return array(FALSE);

   $pics = array();
   $rss  = strstr($page, 'rss+xml');
   $rss  = strstr($rss, 'http://');
   $rss  = substr($rss, 0, strpos($rss, '"'));
   $xml  = file_get_contents($rss);
   $sxml = simplexml_load_string($xml);

   foreach($sxml->entry as $item)
   {
      for ($j=0 ; $j < sizeof($item->link) ; ++$j)
      {
         if (strstr($item->link[$j]['type'], 'image'))
         {
            $t=str_replace('_m', '', $item->link[$j]['href']);
            $t=str_replace('_t', '', $t);
            $pics[]=$t;
         }
      }
   }
   
   return array(count($pics), $pics);
}

?>

插件说明:

插件接受一组图像的URL地址,返回一段Javascript代码,实现图像的幻灯片式显示。他需要以下参数:

$images:一组图像的URL地址。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值