← Tutti gli articoli
Fresh Sliding Thumbnails Gallery with jQuery and ASP.NET
06 April 2011 ·
Asp.Net · Article ·
1186 visite
In this tutorial we are going to create the Asp.Net version of the Fresh Sliding Thumbnails Gallery.
You can found more information on the original site :
I modified the original javascript function buildThumbs in the jquery.gallery.js
- function buildThumbs() {
- current = 1;
- $('#imageWrapper').empty();
- $('#loading').show();
- $.ajax({
- type: "POST",
- url: "WSGallery.asmx/GetFreshSlidingGalleryImages",
- data: "{ AlbumId:'" + album + "' }",
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- async: false,
- success: function (data) {
- var dataobj = (typeof data.d) == 'string' ? eval('(' + data.d + ')') : data.d;
- ////var data = jQuery.parseJSON(data2.d); /* eval('(' + data2 + ')');*/
- //var n = data.d.length;
- var countImages = dataobj.length;
- var count = 0;
- var $tContainer = $('<div/>', { id: 'thumbsContainer', style: 'visibility:hidden;' })
- for (var i = 0; i < countImages; ++i) {
- try {
- var description = dataobj[i].desc[0];
- } catch (e) {
- description = '';
- }
- if (description == undefined)
- description = '';
- $('<img title="' + description + '" alt="' + dataobj[i].alt + '" height="75" />').load(function () {
- var $this = $(this);
- $tContainer.append($this);
- ++count;
- if (count == 1) {
- /* load 1 image into container*/
- $('<img id="displayed" style="display:block;" class="cursorPlus"/>').load(function () {
- var $first = $(this);
- $('#loading').hide();
- resize($first, 0);
- $('#imageWrapper').append($first);
- $('#description').html($this.attr('title'));
- }).attr('src', $this.attr('alt'));
- }
- if (count == countImages) {
- $('#thumbsWrapper').empty().append($tContainer);
- thumbsDim($tContainer);
- makeScrollable($('#thumbsWrapper'), $tContainer, 15);
- }
- }).attr('src', dataobj[i].src);
- }
- },
- error: function (msg) {
- alert(msg);
- }
- });
- ////,'json');
- }
To work this function needs WSGallery.asmx web services:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Services;
- using System.Web.Script.Services;
- using System.IO;
- using System.Web.Script.Serialization;
- namespace FreshSlidingThumbnailsGallery
- {
- /// <summary>
- /// Summary description for WSGallery
- /// </summary>
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [System.ComponentModel.ToolboxItem(false)]
- // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
- [System.Web.Script.Services.ScriptService]
- public class WSGallery : System.Web.Services.WebService
- {
- [WebMethod , ScriptMethod(ResponseFormatResponseFormat = ResponseFormat.Json)]
- public List<cFreshSlidingImageGallery> GetFreshSlidingGalleryImages(string AlbumId) ///int GalleryID)
- {
- string albumName = AlbumId;
- List<cFreshSlidingImageGallery> galleryimages = new List<cFreshSlidingImageGallery>();
- DirectoryInfo di = new DirectoryInfo(Server.MapPath("thumbs/" + albumName));
- FileInfo[] rgFiles = di.GetFiles("*.jpg");
- string thumbsurl = "thumbs/" + albumName + "/";
- string imagesurl = "images/" + albumName + "/";
- foreach (FileInfo fi in rgFiles)
- {
- //Response.Write("<br><a href=" + fi.Name + ">" + fi.Name + "</a>");
- galleryimages.Add(new cFreshSlidingImageGallery(thumbsurl + fi.Name, imagesurl + fi.Name, "desc" + fi.Name));
- }
- return galleryimages;
- /*
- JavaScriptSerializer js = new JavaScriptSerializer();
- string ret= js.Serialize(galleryimages);
- return ret;
- */
- }
- }
- }
Below you can download the Visual Studio 2010 solution.