I have a folder with over 500 images, I want to display the images into a slider. usually the long method is to write the names of all the 500 files and then get it displayed bu then i want to increase the images sizes to lets say over 1000 then i have to write another 500 names and this continue. so another way is to use a script to get all the names of images starting with img_ and store them into an array and then randomize the array when u press the next button on the slider and display it. i am not able to do that. nothing is being displayed. help please.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<!-- directorySlider Javascript file -->
<script src="js/directorySlider.js"></script>
<script src="js/directorySlider.min.js"></script>
<script>
$('#slider-main').directorySlider({
animation: 'fade',
filebase: 'img_',
directory: 'images/',
extension: 'jpg',
numslides: 5,
height: 240,
width: 320,
timeout: 2000
})
</script>
</head>
<body>
<div class="directorySlider" id="slider-main"></div>
</body>
</html>
What I have tried:
(function($){
var directorySlider = function(element, options)
{
var elem = $(element),
obj = this,
elemId = elem[0].id;
var config = $.extend({
animation: 'slide',
filebase: 'slide_',
extension: 'jpg',
speed: 1000,
timeout: 4000,
directory: null,
numslides: null,
height: null,
width: null
}, options || {});
if (config.height) {
$(elem).css('height', config.height);
}
if (config.width) {
$(elem).css('width', config.width);
}
$(elem).css('overflow', 'hidden');
var slides = [],
slideNumber = 1;
while(slideNumber <= config.numslides){
slides.push('<img src="' + config.directory + config.filebase + slideNumber + '.' + config.extension + '" />');
slideNumber++;
}
var slideWrap = $('<div class="' + elemId + '-slide-wrap"></div>');
slideWrap.appendTo(elem);
$.each(slides, function(index, val) {
$(val).css({
position: 'absolute',
top: 0,
left: 0,
width: config.width
}).appendTo(slideWrap);
});
setInterval(function(){
var firstSlide = elem.find('img:first-child'),
lastSlide = elem.find('img:last-child');
switch(config.animation){
case 'fade':
$(lastSlide).animate({
opacity: 0},
config.speed, function() {
$(this).insertBefore(firstSlide).css('opacity', 1);
});
break;
case 'uncover':
lastSlide.animate({
marginLeft: -$(this).width()},
config.speed, function() {
$(this).insertBefore(firstSlide).css('marginLeft', 0);
});
break;
default:
$(lastSlide).animate({
opacity: 0},
config.speed, function() {
$(this).insertBefore(firstSlide).css('opacity', 1);
});
}
}, config.timeout);
};
$.fn.directorySlider = function(options)
{
return this.each(function()
{
var element = $(this);
if (element.data('directoryslider')) return;
var directoryslider = new directorySlider(this, options);
element.data('directoryslider', directoryslider);
});
};
})(jQuery);
this is the javascript. still it won't show any output