Hi,
This is the first script that I trying to read and learn how it function. I not very familiar with JQuery
. I'm more in PHP
. But I notice other members know other languages beside PHP
. So I'm trying to do what other Developer are doing which is knowing another languages.
This is a simple JQuery image code that I found online. The issue is that I am trying to make the ALT
appear with the image at the same time. So what I did I add .text(this.alt)
to make the text appear but it won't work.
Here is the code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<style>
.slideshow img { display: none; cursor: pointer; }
</style>
<script type="text/javascript">
jQuery(function($){
//click image goes to previous slide
$('a.prev').click(function() {
prevSlide($(this).parents('.slideshow').find('.slides'));
});
//click image goes to next slide
$('a.next, .slideshow img').click(function() {
nextSlide($(this).parents('.slideshow').find('.slides'));
});
//initialize show
iniShow();
function iniShow() {
//show first image
$('.slideshow').each(function() {
$(this).find.text(('img:first').fadeIn(500).alt)
})
}
//show previous slide with caption
function prevSlide($slides) {
$slides.find('img:last').text(this.alt).prependTo($slides);
showSlide($slides);
}
//show next slide with caption
function nextSlide($slides) {
$slides.find('img:first').text('').appendTo($slides);
showSlide($slides);
}
//show slides
function showSlide($slides) {
//hide (reset) all slides with caption
$slides.find('img').hide().text('');
//fade in next slide caption
$slides.find('img:first').text('').fadeIn(500);
}
});
</script>
<body>
<div class="slideshow">
<div class="slides">
<img src="images/01.jpg" width="300" height="500" alt="Caption 1 Image is ..." />
<img src="images/02.jpg" width="200" height="500" alt="Caption 2 Image is ..." />
<img src="images/03.jpg" width="500" height="500" alt="Caption 3 Image is ..." />
<img src="images/04.jpg" width="500" height="500" alt="Caption 4 Image is ..." />
</div>
<div class="controls">
<a class="prev" href="javascript:void(0);">Previous</a> |
<a class="next" href="javascript:void(0);">Next</a>
</div>
</div>
</body>
</html>
Any suggestions and explanation would be appreciated. So I can see what I did wrong. Thanks!