使用SmoothGallery创建相册

Creating photo albums using SmoothGallery
Creating photo albums using SmoothGallery

SmoothGallery photo gallery. Today we will continue creating photo albums using different plugins. Next gallery will SmoothGallery. This is free plugin too. This plugin don`t using jQuery how we can expect last time, but it using mootools library. This gallery is html library (not flash), but, anyway – it have very nice interface and rich possibilities. I will tell you how you can apply this gallery for your projects using PHP for generation necessary code.

SmoothGallery图片库。 今天,我们将继续使用不同的插件创建相册。 下一个画廊将是SmoothGallery 。 这也是免费的插件。 这个插件没有使用jQuery,我们上次是怎么期望的,而是使用mootools库。 这个画廊是html库(不是Flash),但是无论如何-它具有非常好的界面和丰富的可能性。 我将告诉您如何使用PHP为您的项目应用此库,以生成必要的代码。

Here are samples and downloadable package:

以下是示例和可下载的软件包:

现场演示
现场演示2

[sociallocker]

[社交储物柜]

打包下载

[/sociallocker]

[/ sociallocker]

Ok, download the example files and lets start coding !

好的,下载示例文件并开始编码!

步骤1. PHP (Step 1. PHP)

Today we will prepare all necessary code directly in single PHP file. Here are code for first sample:

今天,我们将在单个PHP文件中直接准备所有必需的代码。 这是第一个示例的代码:

index.php (index.php)

<?
$sTemplate = <<<XML
<div class="imageElement">
    <h3>{title}</h3>
    <p>{description}</p>
    <a href="#" title="open image" class="open"></a>
    <img src="{fileurl}" class="full" />
    <img src="{fileurl}" class="thumbnail" />
</div>
XML;
$aUnits = array(
    'image 1' => array('Image 1 description', 'pic1.jpg'),
    'image 2' => array('Image 2 description', 'pic2.jpg'),
    'image 3' => array('Image 3 description', 'pic3.jpg'),
    'image 4' => array('Image 4 description', 'pic4.jpg'),
    'image 5' => array('Image 5 description', 'pic5.jpg')
);
$sGalleryObjects = '';
$sFolder = 'data_images/';
foreach ($aUnits as $sTitle => $aUnitInfo) {
    list($sDescription, $sFileName) = $aUnitInfo;
    $sFilePath = $sFolder . $sFileName;
    $sGalleryObjects .= strtr($sTemplate, array('{fileurl}' => $sFilePath, '{title}' => $sTitle, '{description}' => $sDescription));
}
echo <<<EOF
<link rel="stylesheet" href="css/main.css" type="text/css" />
<link rel="stylesheet" href="css/jd.gallery.css" type="text/css" />
<script src="js/mootools-1.2.1-core-yc.js" type="text/javascript"></script>
<script src="js/mootools-1.2-more.js" type="text/javascript"></script>
<script src="js/jd.gallery.js" type="text/javascript"></script>
<div class="example">
    <h3><a href="#">SmoothGallery examples. First - single gallery, second - multiple galleries</a></h3>
    <div>
        <div id="single_gallery">
            {$sGalleryObjects}
        </div>
        <script type="text/javascript">
            function startGallery() {
                var myGal1 = new gallery($('single_gallery'), {
                    timed: true,
                    delay: 5000,
                    embedLinks: false
                });
            }
            window.addEvent('domready',startGallery);
        </script>
    </div>
</div>
EOF;
?>

<?
$sTemplate = <<<XML
<div class="imageElement">
    <h3>{title}</h3>
    <p>{description}</p>
    <a href="#" title="open image" class="open"></a>
    <img src="{fileurl}" class="full" />
    <img src="{fileurl}" class="thumbnail" />
</div>
XML;
$aUnits = array(
    'image 1' => array('Image 1 description', 'pic1.jpg'),
    'image 2' => array('Image 2 description', 'pic2.jpg'),
    'image 3' => array('Image 3 description', 'pic3.jpg'),
    'image 4' => array('Image 4 description', 'pic4.jpg'),
    'image 5' => array('Image 5 description', 'pic5.jpg')
);
$sGalleryObjects = '';
$sFolder = 'data_images/';
foreach ($aUnits as $sTitle => $aUnitInfo) {
    list($sDescription, $sFileName) = $aUnitInfo;
    $sFilePath = $sFolder . $sFileName;
    $sGalleryObjects .= strtr($sTemplate, array('{fileurl}' => $sFilePath, '{title}' => $sTitle, '{description}' => $sDescription));
}
echo <<<EOF
<link rel="stylesheet" href="css/main.css" type="text/css" />
<link rel="stylesheet" href="css/jd.gallery.css" type="text/css" />
<script src="js/mootools-1.2.1-core-yc.js" type="text/javascript"></script>
<script src="js/mootools-1.2-more.js" type="text/javascript"></script>
<script src="js/jd.gallery.js" type="text/javascript"></script>
<div class="example">
    <h3><a href="#">SmoothGallery examples. First - single gallery, second - multiple galleries</a></h3>
    <div>
        <div id="single_gallery">
            {$sGalleryObjects}
        </div>
        <script type="text/javascript">
            function startGallery() {
                var myGal1 = new gallery($('single_gallery'), {
                    timed: true,
                    delay: 5000,
                    embedLinks: false
                });
            }
            window.addEvent('domready',startGallery);
        </script>
    </div>
</div>
EOF;
?>

So, what I doing here: In begining – I defined template for units of images for gallery. After – defined array of used images. This is only for current sample. In your script all can be different (should be). In result – in foreach cycle we prepared list of images using our template for our gallery. And, after, drawing our result. Pay attention to our javascript, where we perform initialization of our gallery. Don`t forget, that today we don`t using jQuery, but using mootools library (it using $ symbol too). In params I set that images will switching by time with delay in 5 second. This gallery can accept very many different params, here are several of them:

因此,我在这里所做的事情:一开始-我定义了用于画廊图像单位的模板。 之后–定义已使用图像的数组。 这仅适用于当前样本。 在脚本中,所有内容都可以不同(应该是)。 结果–在foreach周期中,我们使用了用于画廊的模板来准备图像列表。 然后,得出我们的结果。 请注意我们JavaScript,我们在其中执行画廊的初始化。 不要忘记,今天我们不使用jQuery,而是使用mootools库(它也使用$符号)。 在参数中,我设置为图像将在5秒内按时间切换。 这个画廊可以接受很多不同的参数,其中有几个:

  • showArrows – show navigation arrows?, default value ‘true’

    showArrows –显示导航箭头?,默认值为“ true”
  • showCarousel – show carousel?, default value ‘true’

    showCarousel –显示轮播吗?,默认值为'true'
  • showInfopane – show info panel?, default value ‘true’

    showInfopane –显示信息面板?,默认值为“ true”
  • fadeDuration – fade duration, default value ‘500’

    fadeDuration –淡入时间,默认值为“ 500”
  • timed – are images switching by time?, default value ‘false’

    定时-图像是否按时间切换?默认值为“ false”
  • delay – delay between images, default value ‘9000’

    延迟–图像之间的延迟,默认值为'9000'
  • titleSelector – selector for title elements (check our template for units), default value ‘h3’

    titleSelector –标题元素的选择器(检查我们的模板的单位),默认值为“ h3”
  • slideInfoZoneOpacity – default value ‘0.7’

    slideInfoZoneOpacity –默认值“ 0.7”
  • slideInfoZoneSlide – default value ‘true’

    slideInfoZoneSlide –默认值“ true”
  • carouselMinimizedOpacity – min opacity in carousel, default value ‘0.4’

    carouselMinimizedOpacity –轮播中的最小不透明度,默认值为'0.4'
  • carouselMaximizedOpacity – max onhover opacity in carousel, default value ‘0.9’

    carouselMaximizedOpacity –轮播中的最大悬停不透明度,默认值为'0.9'
  • textShowCarousel – title to carousel element, default value ‘Pictures’

    textShowCarousel –轮播元素的标题,默认值为'Pictures'
  • textPreloadingCarousel – title for preloading of carousel, default value ”Loading…’

    textPreloadingCarousel –轮播的预加载标题,默认值为“ Loading…”

I hope that you will able to apply necessary custom params by self. Now, want to tell, that this plugin allow to draw not only single gallery, but also multiple galleries too, here are sources of our second sample:

我希望您能够自行应用必要的自定义参数。 现在,要告诉我们的是,此插件不仅可以绘制单个画廊,而且还可以绘制多个画廊,这是我们第二个示例的来源:

index-2.php (index-2.php)

<?
$sTemplate = <<<XML
<div class="imageElement">
    <h3>{title}</h3>
    <p>{description}</p>
    <a href="#" title="open image" class="open"></a>
    <img src="{fileurl}" class="full" />
    <img src="{fileurl}" class="thumbnail" />
</div>
XML;
$aUnits = array(
    'Album #1' => array(
        'image 1' => array('Image 1 description', 'pic1.jpg'),
        'image 2' => array('Image 2 description', 'pic2.jpg'),
        'image 3' => array('Image 3 description', 'pic3.jpg'),
        'image 4' => array('Image 4 description', 'pic4.jpg'),
        'image 5' => array('Image 5 description', 'pic5.jpg'),
        'image 6' => array('Image 6 description', 'pic6.jpg')
    ),
    'Album #2' => array(
        'image 7' => array('Image 7 description', 'pic7.jpg'),
        'image 8' => array('Image 8 description', 'pic8.jpg'),
        'image 9' => array('Image 9 description', 'pic9.jpg'),
        'image 10' => array('Image 10 description', 'pic10.jpg'),
        'image 11' => array('Image 11 description', 'pic11.jpg'),
        'image 12' => array('Image 12 description', 'pic12.jpg')
    ),
    'Album #3' => array(
        'image 13' => array('Image 13 description', 'pic13.jpg'),
        'image 14' => array('Image 14 description', 'pic14.jpg'),
        'image 15' => array('Image 15 description', 'pic15.jpg'),
        'image 16' => array('Image 16 description', 'pic16.jpg'),
        'image 17' => array('Image 17 description', 'pic17.jpg'),
        'image 18' => array('Image 18 description', 'pic18.jpg')
    )
);
$sGalleryObjects = '';
$sFolder = 'data_images/';
foreach ($aUnits as $sAlbumTitle => $aAlbums) {
    $sGalleryObjects .= '<div id="'.$sAlbumTitle.'" class="galleryElement"><h2>'.$sAlbumTitle.'</h2>';
    foreach ($aAlbums as $sTitle => $aUnitInfo) {
        list($sDescription, $sFileName) = $aUnitInfo;
        $sFilePath = $sFolder . $sFileName;
        $sGalleryObjects .= strtr($sTemplate, array('{fileurl}' => $sFilePath, '{title}' => $sTitle, '{description}' => $sDescription));
    }
    $sGalleryObjects .= '</div>';
}
echo <<<EOF
<link rel="stylesheet" href="css/main.css" type="text/css" />
<link rel="stylesheet" href="css/jd.gallery.css" type="text/css" />
<script src="js/mootools-1.2.1-core-yc.js" type="text/javascript"></script>
<script src="js/mootools-1.2-more.js" type="text/javascript"></script>
<script src="js/jd.gallery.js" type="text/javascript"></script>
<script src="js/jd.gallery.set.js" type="text/javascript"></script>
<div class="example">
    <h3><a href="#">SmoothGallery examples. First - single gallery, second - multiple galleries</a></h3>
    <div>
        <div id="multiple_galleries">
            {$sGalleryObjects}
        </div>
        <script type="text/javascript">
            function startGallery() {
                var myGal2 = new gallerySet($('multiple_galleries'), {
                    timed: true,
                    delay: 5000,
                    embedLinks: false
                });
            }
            window.addEvent('domready',startGallery);
        </script>
    </div>
</div>
EOF;
?>

<?
$sTemplate = <<<XML
<div class="imageElement">
    <h3>{title}</h3>
    <p>{description}</p>
    <a href="#" title="open image" class="open"></a>
    <img src="{fileurl}" class="full" />
    <img src="{fileurl}" class="thumbnail" />
</div>
XML;
$aUnits = array(
    'Album #1' => array(
        'image 1' => array('Image 1 description', 'pic1.jpg'),
        'image 2' => array('Image 2 description', 'pic2.jpg'),
        'image 3' => array('Image 3 description', 'pic3.jpg'),
        'image 4' => array('Image 4 description', 'pic4.jpg'),
        'image 5' => array('Image 5 description', 'pic5.jpg'),
        'image 6' => array('Image 6 description', 'pic6.jpg')
    ),
    'Album #2' => array(
        'image 7' => array('Image 7 description', 'pic7.jpg'),
        'image 8' => array('Image 8 description', 'pic8.jpg'),
        'image 9' => array('Image 9 description', 'pic9.jpg'),
        'image 10' => array('Image 10 description', 'pic10.jpg'),
        'image 11' => array('Image 11 description', 'pic11.jpg'),
        'image 12' => array('Image 12 description', 'pic12.jpg')
    ),
    'Album #3' => array(
        'image 13' => array('Image 13 description', 'pic13.jpg'),
        'image 14' => array('Image 14 description', 'pic14.jpg'),
        'image 15' => array('Image 15 description', 'pic15.jpg'),
        'image 16' => array('Image 16 description', 'pic16.jpg'),
        'image 17' => array('Image 17 description', 'pic17.jpg'),
        'image 18' => array('Image 18 description', 'pic18.jpg')
    )
);
$sGalleryObjects = '';
$sFolder = 'data_images/';
foreach ($aUnits as $sAlbumTitle => $aAlbums) {
    $sGalleryObjects .= '<div id="'.$sAlbumTitle.'" class="galleryElement"><h2>'.$sAlbumTitle.'</h2>';
    foreach ($aAlbums as $sTitle => $aUnitInfo) {
        list($sDescription, $sFileName) = $aUnitInfo;
        $sFilePath = $sFolder . $sFileName;
        $sGalleryObjects .= strtr($sTemplate, array('{fileurl}' => $sFilePath, '{title}' => $sTitle, '{description}' => $sDescription));
    }
    $sGalleryObjects .= '</div>';
}
echo <<<EOF
<link rel="stylesheet" href="css/main.css" type="text/css" />
<link rel="stylesheet" href="css/jd.gallery.css" type="text/css" />
<script src="js/mootools-1.2.1-core-yc.js" type="text/javascript"></script>
<script src="js/mootools-1.2-more.js" type="text/javascript"></script>
<script src="js/jd.gallery.js" type="text/javascript"></script>
<script src="js/jd.gallery.set.js" type="text/javascript"></script>
<div class="example">
    <h3><a href="#">SmoothGallery examples. First - single gallery, second - multiple galleries</a></h3>
    <div>
        <div id="multiple_galleries">
            {$sGalleryObjects}
        </div>
        <script type="text/javascript">
            function startGallery() {
                var myGal2 = new gallerySet($('multiple_galleries'), {
                    timed: true,
                    delay: 5000,
                    embedLinks: false
                });
            }
            window.addEvent('domready',startGallery);
        </script>
    </div>
</div>
EOF;
?>

As you can see, our main array now contain 1 more level, and now we can see here and albums and its photos. Plus, I changed parser a little too. Also, pay attention to javascript initialization – it changed a little too. But, commonly all still same, just few another custom params like:

如您所见,我们的主阵列现在包含了另外1个关卡,现在我们可以在这里看到专辑和它的照片。 另外,我也稍微改变了解析器。 另外,请注意javascript初始化-它也发生了一些变化。 但是,通常都还是一样,只有几个其他自定义参数,例如:

  • galleryTitleSelector – selector for gallery title, default value ‘h2’

    galleryTitleSelector –画廊标题的选择器,默认值为“ h2”
  • textGallerySelector – main title at list of albums, default value ‘Galleries’

    textGallerySelector –相册列表中的主要标题,默认值为“ Galleries”
  • textShowCarousel – title in carousel, default value ‘{0}/{1} Pictures’

    textShowCarousel –轮播中的标题,默认值为'{0} / {1}图片'

步骤2. CSS (Step 2. CSS)

Here are used CSS files for our demo:

这是我们的演示使用CSS文件:

css / main.css (css/main.css)

body{background:#eee;font-family:Verdana, Helvetica, Arial, sans-serif;margin:0;padding:0}
.example{background:#FFF;width:800px;font-size:80%;border:1px #000 solid;margin:20px auto;padding:15px;-moz-border-radius: 3px;-webkit-border-radius: 3px}
.example #single_gallery, .example #multiple_galleries {
border: 1px solid #000000;
-moz-border-radius: 6px;-webkit-border-radius: 6px;
height: 500px;
width: 100%;
overflow:hidden;
}
/*small fixes for gallery itself using css3*/
.jdGallery .carousel .carouselInner .thumbnail, .jdExtCarousel .carouselInner .thumbnail {
background-size:100px 75px !important;
}
.jdGallery .gallerySelector .gallerySelectorInner div.galleryButton div.preview {
background-size:40px 40px !important;
}

body{background:#eee;font-family:Verdana, Helvetica, Arial, sans-serif;margin:0;padding:0}
.example{background:#FFF;width:800px;font-size:80%;border:1px #000 solid;margin:20px auto;padding:15px;-moz-border-radius: 3px;-webkit-border-radius: 3px}
.example #single_gallery, .example #multiple_galleries {
border: 1px solid #000000;
-moz-border-radius: 6px;-webkit-border-radius: 6px;
height: 500px;
width: 100%;
overflow:hidden;
}
/*small fixes for gallery itself using css3*/
.jdGallery .carousel .carouselInner .thumbnail, .jdExtCarousel .carouselInner .thumbnail {
background-size:100px 75px !important;
}
.jdGallery .gallerySelector .gallerySelectorInner div.galleryButton div.preview {
background-size:40px 40px !important;
}

As you can see – I made 2 small fixes for styles of this gallery – it will allow us don`t use small images for thumbs in carousel and for list of albums

如您所见-我为该画廊的风格做了2个小修正-它使我们不要将小图像用于轮播中的拇指和专辑列表

css / jd.gallery.css (css/jd.gallery.css)

This file belong to our plugin and already available in package

该文件属于我们的插件,已经在软件包中提供

步骤3. JS (Step 3. JS)

All JS files (of this plugin) located in ‘js’ folder:

位于“ js”文件夹中的所有(该插件的)JS文件:

js / jd.gallery.js,js / jd.gallery.set.js,js / mootools-1.2-more.js和js / mootools-1.2.1-core-yc.js (js/jd.gallery.js, js/jd.gallery.set.js, js/mootools-1.2-more.js and js/mootools-1.2.1-core-yc.js)

All these files available in download package.

所有这些文件都在下载包中。

步骤4.图片 (Step 4. Images)

All our images located in ‘data_images’ folder. Of course, you can use another folder path and name. Just don`t forget to correct php files in this case too.

我们所有的图像都位于“ data_images”文件夹中。 当然,您可以使用其他文件夹路径和名称。 只是不要忘了在这种情况下也要更正php文件。

现场演示
现场演示2

结论 (Conclusion)

Today I told you how you can create photo albums for your websites. Sure that it was interesting. Good luck!

今天,我告诉您如何为您的网站创建相册。 当然,这很有趣。 祝好运!

翻译自: https://www.script-tutorials.com/creating-photo-albums-using-smoothgallery/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值