Thursday 13 December 2012

JQuery to Display Slide Show Images within fixed size SharePoint 2010


The Slide Show Web part displays the images from the given picture library with its actual size i.e the size of the Slide Show Web part varies according to the size of the image. We can restrict the size of the web part through Edit Web Part properties but this does not change the size of the image. To display the whole image within that restricted area we have to change the height & width of the image during runtime to fit to the size. Only change the image size will not display the image in the middle position. To do this we first have to change the size of the table td tag to fit to the Slide Show Web Part screen.

Below script first sets the size of the table td tag & then sets the size of the image.

<script type="text/javascript">

$(document).ready(function() {   
//get the ID of the DIV inside td within which the slide show web part is present
var tdlist=$("div[id^='WebPartct100']");
var currtd=$("td[id$='td']"); tdlist.height('100%');  
tdlist.width('100%');  
//assign the height & width to the td
currtd.height('150px');  
currtd.width('240px');
//get the ID of the DIV of slide show web part

var divList = $("div[id^='MSOPictureLibrarySlideshowWebPart']");  
var currImage= $("img[id$='curr']");  
divList.height('100%');  
divList.width('100%');  
//assign the height & width to the image
currImage.height('130px');  
currImage.width('230px');  
});


</script>

2 comments:

  1. This is not working. would you please specify which div ID to copy into the code. I do not see any on opening the page in designer.

    ReplyDelete