Hi
I recently created a JQuery Gallery Script
in the Javascript
section with some help from pritaeas & JJenZz:
Here is the link to the script:
The JQuery
code works you can check the link and test it out.
Since the script is in JQuery
. I want to add PHP
code with it. Another words I want to combine PHP & JQuery
This is the changes I made from this:
<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>
to this:
$image = array(array('image'=>'T1.jpg','alt'=>'Time'),
array('image'=>'I2.jpg','alt'=>'To'),
array('image'=>'M3.jpg','alt'=>'Tell'),
array('image'=>'E4.jpg','alt'=>'Toke'));
$alt = array(array('alt'=>'Time'),
array('alt'=>'To'),
array('alt'=>'Tell'),
array('alt'=>'Toke'));
<img src="images/<?php echo $image;?>.jpg" alt="<?php echo $alt;?>" />
I'm having issue echo <img> & <alt>
together.
Here is my update example:
<!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>
<link href="css/style.css" type="text/css" rel="stylesheet">
</head>
<style type="text/css">
.slideshow img { display: none; cursor: pointer; }
</style>
<script type="text/javascript">
jQuery(function($){
//clicking prev button goes to previous slide
$('.slideshow .prev').click(function() {
prevSlide($(this).parents('.slideshow').find('.slides'));
});
//clicking next button or image goes to next slide
$('.slideshow .next, .slideshow img,').click(function() {
nextSlide($(this).parents('.slideshow').find('.slides'));
});
//initialize show
iniShow();
function iniShow() {
// show first slide with caption
$('.slideshow').each(function() {
showSlide($(this).find('.slides'));
});
}
// move previous slide to top of stack and call showSlide
function prevSlide($slides) {
$slides.find('img:last').prependTo($slides);
showSlide($slides);
}
// move next slide to top of stack and call showSlide
function nextSlide($slides) {
$slides.find('img:first').appendTo($slides);
showSlide($slides);
}
// show slide with caption
function showSlide($slides) {
var $nextSlide = $slides.find('img:first');
//hide (reset) all slides
$slides.find('img').hide();
//fade in next slide
$nextSlide.fadeIn(500);
//show caption
$('#caption').text($nextSlide[0].alt);
}
});
</script>
<body>
<?php
$image = array(array('image'=>'T1.jpg'),
array('image'=>'I2.jpg'),
array('image'=>'M3.jpg'),
array('image'=>'E4.jpg'));
$alt = array(array('alt'=>'Time'),
array('alt'=>'To'),
array('alt'=>'Tell'),
array('alt'=>'Toke'));
?>
<div class="slideshow">
<div class="slides">
<img src="images/<?php echo $image;?>.jpg" alt="<?php echo $alt;?>" />
</div>
<p id="caption"></p>
<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 will help. I appreciate it. Thanks!