I tested this script in normal .php file but when put code in wordpress header file script doesn't worked.
Can someone show me how to put CarouFredSel slider inside wordpress theme?
Here is the code i used in .php file and all works just fine:
<!-- include jQuery + carouFredSel plugin -->
<script type="text/javascript" language="javascript" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript" language="javascript" src="jquery.carouFredSel-6.2.1-packed.js"></script>
<!-- optionally include helper plugins -->
<script type="text/javascript" language="javascript" src="helper-plugins/jquery.mousewheel.min.js"></script>
<script type="text/javascript" language="javascript" src="helper-plugins/jquery.touchSwipe.min.js"></script>
<script type="text/javascript" language="javascript" src="helper-plugins/jquery.transit.min.js"></script>
<script type="text/javascript" language="javascript" src="helper-plugins/jquery.ba-throttle-debounce.min.js"></script>
<!-- fire plugin onDocumentReady -->
<script type="text/javascript" language="javascript">
$(function() {
// Basic carousel, no options
$('#foo0').carouFredSel();
// Basic carousel + timer, using CSS-transitions
$('#foo1').carouFredSel({
auto: {
pauseOnHover: 'resume',
progress: '#timer1'
}
}, {
transition: true
});
// Scrolled by user interaction
$('#foo2').carouFredSel({
auto: false,
prev: '#prev2',
next: '#next2',
pagination: "#pager2",
mousewheel: true,
swipe: {
onMouse: true,
onTouch: true
}
});
// Variable number of visible items with variable sizes
$('#foo3').carouFredSel({
width: 360,
height: 'auto',
prev: '#prev3',
next: '#next3',
auto: false
});
// Responsive layout, resizing the items
$('#foo4').carouFredSel({
responsive: true,
width: '100%',
scroll: 2,
items: {
width: 400,
// height: '30%', // optionally resize item-height
visible: {
min: 2,
max: 6
}
}
});
// Fuild layout, centering the items
$('#foo5').carouFredSel({
width: '100%',
scroll: 2
});
});
</script>
<style type="text/css" media="all">
.list_carousel {
background-color: #ccc;
margin: 0 0 30px 60px;
width: 900px;
}
.list_carousel ul {
margin: 0;
padding: 0;
list-style: none;
display: block;
}
.list_carousel li {
font-size: 40px;
color: #999;
text-align: center;
background-color: #eee;
border: 5px solid #999;
width: 400px;
height: 400px;
padding: 0;
margin: 6px;
display: block;
float: left;
}
.list_carousel.responsive {
width: auto;
margin-left: 0;
}
.clearfix {
float: none;
clear: both;
}
</style>
<p>Basic carousel.</p>
<div class="list_carousel">
<ul id="foo1">
<?php
$html = "";
$url = "http://rss.dnevnik.hr/index.rss";
$xml = simplexml_load_file($url);
for ($i = 0; $i <10; $i++) {
$title = $xml->channel->item[$i]->title;
$link = $xml->channel->item[$i]->link;
$opis = $xml->channel->item[$i]->description;
$html .= "<li><div><a href='$link'><h3>$opis<h3></a></div></li>";}
echo $html;
?>
</ul>
<div class="clearfix"></div>
</div>
<br />
Related
I am very new to jquery and ajax. Trying to implement selectize plugin that would query the database and return the values as dropdown. In order to do that, here is my php code that brings back data from the table. If I type the url for this php page and pass parameters, it brings back data in json format. {"movies":"value1"}{"movies":"value2"} .....
$q = $_GET['query'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT column_name from table where segment_name like '%$q%'";
$result = $conn->query($sql);
error_reporting(0);
$name->movies = "";
if ($result->num_rows > 0) {
// output data of each row
while($segment_name = $result->fetch_assoc()) {
$name->movies = $segment_name["segment_name"];
$movies = json_encode($name);
echo $movies;
}
} else {
echo "0 results";
}
$conn->close();
And, here is the jQuery code from the selectize plugin.
<!DOCTYPE html>
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7"><![endif]-->
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8"><![endif]-->
<!--[if IE 8]><html class="no-js lt-ie9"><![endif]-->
<!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Selectize.js Demo</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/stylesheet.css">
<!--[if IE 8]><script src="js/es5.js"></script><![endif]-->
<script src="js/jquery.min.js"></script>
<script src="../dist/js/standalone/selectize.js"></script>
<script src="js/index.js"></script>
<style type="text/css">
.selectize-control.movies .selectize-dropdown [data-selectable] {
border-bottom: 1px solid rgba(0,0,0,0.05);
height: 60px;
position: relative;
-webkit-box-sizing: content-box;
box-sizing: content-box;
padding: 10px 10px 10px 60px;
}
.selectize-control.movies .selectize-dropdown [data-selectable]:last-child {
border-bottom: 0 none;
}
.selectize-control.movies .selectize-dropdown .by {
font-size: 11px;
opacity: 0.8;
}
.selectize-control.movies .selectize-dropdown .by::before {
content: 'by ';
}
.selectize-control.movies .selectize-dropdown .name {
font-weight: bold;
margin-right: 5px;
}
.selectize-control.movies .selectize-dropdown .description {
font-size: 12px;
color: #a0a0a0;
}
.selectize-control.movies .selectize-dropdown .actors,
.selectize-control.movies .selectize-dropdown .description,
.selectize-control.movies .selectize-dropdown .movies {
display: block;
white-space: nowrap;
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
}
.selectize-control.movies .selectize-dropdown .actors {
font-size: 10px;
color: #a0a0a0;
}
.selectize-control.movies .selectize-dropdown .actors span {
color: #606060;
}
.selectize-control.movies .selectize-dropdown img {
height: 60px;
left: 10px;
position: absolute;
border-radius: 3px;
background: rgba(0,0,0,0.04);
}
.selectize-control.movies .selectize-dropdown .meta {
list-style: none;
margin: 0;
padding: 0;
font-size: 10px;
}
.selectize-control.movies .selectize-dropdown .meta li {
margin: 0;
padding: 0;
display: inline;
margin-right: 10px;
}
.selectize-control.movies .selectize-dropdown .meta li span {
font-weight: bold;
}
.selectize-control.movies::before {
-moz-transition: opacity 0.2s;
-webkit-transition: opacity 0.2s;
transition: opacity 0.2s;
content: ' ';
z-index: 2;
position: absolute;
display: block;
top: 12px;
right: 34px;
width: 16px;
height: 16px;
background: url(images/spinner.gif);
background-size: 16px 16px;
opacity: 0;
}
.selectize-control.movies.loading::before {
opacity: 0.4;
}
</style>
</head>
<body>
<div id="wrapper">
<h1>Selectize.js</h1>
<div class="demo">
<h2>Loading from API</h2>
<p>This demo shows how to integrate third-party data, loaded asynchronously.</p>
<div class="control-group">
<label for="select-movie">Movie:</label>
<select id="select-movie" class="movies" placeholder="Find a movie..."></select>
</div>
<script>
// <select id="select-movie"></select>
$('#select-movie').selectize({
valueField: 'movies',
labelField: 'movies',
searchField: 'movies',
options: [],
create: false,
render: {
option: function(item, escape) {
return '<div>' +
'<span class="movies">' +
'<span class="name">' + escape(item.movies) + '</span>' +
'</span>' +
'</div>';
}
},
load: function(query, callback) {
if (!query.length) return callback();
$.ajax({
//url: 'http://api.rottentomatoes.com/api/public/v1.0/movies.json',
url:'http://localhost/selectize/examples/myphp.php?query='+ encodeURIComponent(query),
type: 'GET',
dataType: 'jsonp',
data: {
q: query,
//page_limit: 10,
//apikey: '3qqmdwbuswut94jv4eua3j85'
},
error: function() {
callback();
},
success: function(res) {
console.log(res);
callback(res);
alert(res);
}
});
}
});
</script>
</div>
</div>
</body>
</html>
But, now I am lost as to how to make this work. I know I am a newbie so, asking for help.
I have a table with userdata using:
jquery-1.9.1.js
jquery-ui-1.10.1.custom.js
and Christian Bach jquery.tablesorter-update
"jquery.tablesorter-update.js"
When using the demo version of "Modal form", Create new user on the same page as the table (form opens ontop of table),
it looks and works great in Chrome and Safari but the from is distorted in IE8.
Snippet from head:
<!-- CSS for table -->
<style type="text/css">
div#tableBody {
width: 100%;
padding: 0.3em;
font-size:x-small;
}
table {
width: 100%;
}
table th {
padding: 0.3em;
}
table th span {
float:right;
}
table tr.odd {
background-color: #FFFFFF;
}
div.ui-datepicker {
font-size:small;
}
</style>
<!-- jQuery UI Theme Start-->
<link href="../css/redmond/jquery-ui-1.10.1.custom.css" rel="stylesheet">
<script src="../js/jquery-1.9.1.js"></script>
<script src="../js/jquery-ui-1.10.1.custom.js"></script>
<script src="../js/jquery.ui.datepicker-sv.js"></script>
<!-- jQuery UI Theme End-->
<!--Christian Bach jquery.tablesorter-update Star-->
<script type="text/javascript" src="../scripts/jquery.tablesorter-update.js"></script>
<!--Christian Bach jquery.tablesorter-update End-->
<script language="JavaScript">
<!--
function DeleteItem(idurl)
{
go_on = confirm("Are you sure?");
if (go_on)
{
document.location.href=idurl;
}
}
// Tablesort
$(document).ready(function() {
// call the tablesorter plugin
$('#itemTable').tablesorter({
// sort on the first column and third column, order asc
locale: 'eu', widgets: ['zebra'], useUI: true
});
});
//-->
</script>
<style>
body { font-size: 62.5%; }
label, input { display:block; }
input.text { margin-bottom:12px; width:95%; padding: .4em; }
fieldset { padding:0; border:0; margin-top:25px; }
h1 { font-size: 1.2em; margin: .6em 0; }
div#users-contain { width: 350px; margin: 20px 0; }
div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
.ui-dialog .ui-state-error { padding: .3em; }
.validateTips { border: 1px solid transparent; padding: 0.3em; }
</style>
<script>
$(function() {
var name = $( "#name" ),
email = $( "#email" ),
============= complete ripoff from jquery-ui modal form demo
Any suggestions?
I strongly suspect the issue is more the HTML and CSS than anything jQuery is doing because 1.9 is the last version to care about older versions of IE.
That said, I would advise - not just to solve this problem but any future problems with IE bugs - for you to look into a reset.css (okay, before I get stoned to death, it's a better idea to go with normalise.css these days, which you can find here: normalise.css
Admittedly that doesn't specifically tackle your problem, but I'd stick that in there because that will most likely fix your problem and any other potential IE issues.
That said, I'm not sure why you need to specifically set all those widths as a table will take up whatever room it can to fulfill it's 'needs' for width anyway.
I am trying to implement Rotate3Di, found here: http://www.zachstronaut.com/projects/rotate3di/
I can get my images to flip, but the back side is only showing a mirror image of the front and not unique content that I am pulling from a database. Thanks for any help in advance.
<script type="text/javascript" language="javascript" charset="utf-8">
$(document).ready(function () {
$('#movienav li div.back').hide().css('left', 0);
function mySideChange(front) {
if (front) {
$(this).parent().find('div.front').show();
$(this).parent().find('div.back').hide();
} else {
$(this).parent().find('div.front').hide();
$(this).parent().find('div.back').show();
}
}
$('#movienav li').hover(
function () {
$(this).find('div').stop().rotate3Di('flip', 180, 1000, {direction: 'clockwise', sideChange: mySideChange});
},
function () {
$(this).find('div').stop().rotate3Di('unflip', 1000, {sideChange: mySideChange});
}
);
});
</script>
HTML
<div id="movienav">
<ul>
<li><div class="front"><img src="<?php echo $imglink; ?>" width="340" height="450" class="dvdcover" /></div>
<div class="back">
<?php echo $description; ?>
</div>
</li>
</ul>
</div>
CSS
#movienav {
height: 450px;
width:75%;
float:left;
margin-top:25px;
clear:left;
padding-bottom: 45px;
}
#movienav li {
width: 340px;
height: 450px;
float: left;
margin-right: 10px;
position: relative;
display:inline;
list-style:none;
}
#movienav li div {
width: 340px;
height: 450px;
overflow: hidden;
background: #161616;
position: absolute;
top: 0;
left: 0;
}
#movienav li div.back {
left: -999em;
padding-bottom: 15px;
background-color:#161616; /*max-height:450px; overflow:auto;*/
margin-top: 0;
}
SOLVED
Changed above lines to:
$('#movienav li').hover(
function () {
$(this).find('div').stop().rotate3Di('180', 400, {direction: 'clockwise', sideChange: mySideChange});
},
function () {
$(this).find('div').stop().rotate3Di('unflip', 400, {sideChange: mySideChange});
}
);
http://davidwalsh.name/css-flip
I think you want backface-visibility: hidden;
I'll be honest I've only done this via CSS and not with javascript, but I had the same issue at first until I set the backface-visibility. Doing everything via javascript might require some extra magic.
I have a main php file that loads an external php file. This is the code in my main php file:
<php>
<head>
<meta http-equiv="content-type" content="text/php; charset=utf-8" />
<link rel="stylesheet" type="text/css" media="all" href="style.css" />
<script type="text/javascript" src="ajax.js"></script>
<link rel="stylesheet" href="colorbox.css" />
<script src="js/jquery.colorbox.js"></script>
<script src="js/jquery-1.8.2.min.js"></script>
<script src="js/jquery.colorbox-min.js"></script>
<link href="jimgMenukwicks.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-easing-1.3.pack.js"></script>
<script type="text/javascript" src="js/jquery-easing-compatibility.1.2.pack.js"></script>
<script type="text/javascript" src="js/jquery.kwicks-1.5.1.pack.js"></script>
<script type="text/javascript">
$().ready(function() {
$('.jimgMenu ul').kwicks({max: 310, duration: 300, easing: 'easeOutQuad'});
});
</script>
</head>
<div id="tengah" class="jimgMenu" >
<ul>
<li class="landscapes"> </li>
<li class="people"> </li>
<li class="nature"> </li>
</ul>
</div>
<div id="content" class="clearfix shadow">
<div id="sidebar" class="left">
<div id='ResponseDiv'> </div>
<div id="menu" class="inner">
</div>
</div>
<div id="main" class="right">
<h2>Detail</h2>
<div id='ResponseDiv2'> </div>
</div>
</div>
</div>
</php>
I have a function in ajax.js that calls an external php page named ajaxpage. Here the code in ajax.js:
function ajaxpage(url, containerid) {
var page_request = false
if(window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if(window.ActiveXObject) { // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} catch(e) {
try {
page_request = new ActiveXObject("Microsoft.XMLHTTP")
} catch(e) {}
}
} else return false
page_request.onreadystatechange = function () {
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}
function loadpage(page_request, containerid) {
if(page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1)) document.getElementById(containerid).innerHTML = page_request.responseText
}
The problem is when I try to load "7.php" into my main.php the 7.php file is loaded but the animation in 7.php not working.
Does anyone know why this is happening?
this is the content of 7.php
<php>
<html>
<head>
<style type="text/css">
body {
background: #0F0D0D;
padding: 30px 0 0 50px;
}
div.sc_menu_wrapper {
position: relative;
height: 500px;
/* Make bigger than a photo, because we need a place for a scrollbar. */
width: 160px;
margin-top: 30px;
overflow: auto;
}
div.sc_menu {
padding: 15px 0;
}
.sc_menu a {
display: block;
margin-bottom: 5px;
width: 130px;
border: 2px rgb(79, 79, 79) solid;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
/* When image support is turned off */
color: #fff;
background: rgb(79, 79, 79);
}
.sc_menu a:hover {
border-color: rgb(130, 130, 130);
border-style: dotted;
}
.sc_menu img {
display: block;
border: none;
}
.sc_menu_wrapper .loading {
position: absolute;
top: 50px;
left: 10px;
margin: 0 auto;
padding: 10px;
width: 100px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
text-align: center;
color: #fff;
border: 1px solid rgb(79, 79, 79);
background: #1F1D1D;
}
/* Styling tooltip */
.sc_menu_tooltip {
display: block;
position: absolute;
padding: 6px;
font-size: 12px;
color: #fff;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border: 1px solid rgb(79, 79, 79);
background: rgb(0, 0, 0);
/* Make background a bit transparent for browsers that support rgba */
background: rgba(0, 0, 0, 0.5);
}
/* Here are styles for a link to an article. Not for you :) */
#back {
margin-left: 8px;
color: gray;
font-size: 18px;
text-decoration: none;
}
#back:hover {
text-decoration: underline;
}
</style>
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">/*<![CDATA[*/
function makeScrollable(wrapper, scrollable){
// Get jQuery elements
var wrapper = $(wrapper), scrollable = $(scrollable);
// Hide images until they are not loaded
scrollable.hide();
var loading = $('<div class="loading">Loading...</div>').appendTo(wrapper);
// Set function that will check if all images are loaded
var interval = setInterval(function(){
var images = scrollable.find('img');
var completed = 0;
// Counts number of images that are succesfully loaded
images.each(function(){
if (this.complete) completed++;
});
if (completed == images.length){
clearInterval(interval);
// Timeout added to fix problem with Chrome
setTimeout(function(){
loading.hide();
// Remove scrollbars
wrapper.css({overflow: 'hidden'});
scrollable.slideDown('slow', function(){
enable();
});
}, 1000);
}
}, 100);
function enable(){
// height of area at the top at bottom, that don't respond to mousemove
var inactiveMargin = 99;
// Cache for performance
var wrapperWidth = wrapper.width();
var wrapperHeight = wrapper.height();
// Using outer height to include padding too
var scrollableHeight = scrollable.outerHeight() + 2*inactiveMargin;
// Do not cache wrapperOffset, because it can change when user resizes window
// We could use onresize event, but it's just not worth doing that
// var wrapperOffset = wrapper.offset();
// Create a invisible tooltip
var tooltip = $('<div class="sc_menu_tooltip"></div>')
.css('opacity', 0)
.appendTo(wrapper);
// Save menu titles
scrollable.find('a').each(function(){
$(this).data('tooltipText', this.title);
});
// Remove default tooltip
scrollable.find('a').removeAttr('title');
// Remove default tooltip in IE
scrollable.find('img').removeAttr('alt');
var lastTarget;
//When user move mouse over menu
wrapper.mousemove(function(e){
// Save target
lastTarget = e.target;
var wrapperOffset = wrapper.offset();
var tooltipLeft = e.pageX - wrapperOffset.left;
// Do not let tooltip to move out of menu.
// Because overflow is set to hidden, we will not be able too see it
tooltipLeft = Math.min(tooltipLeft, wrapperWidth - 75); //tooltip.outerWidth());
var tooltipTop = e.pageY - wrapperOffset.top + wrapper.scrollTop() - 40;
// Move tooltip under the mouse when we are in the higher part of the menu
if (e.pageY - wrapperOffset.top < wrapperHeight/2){
tooltipTop += 80;
}
tooltip.css({top: tooltipTop, left: tooltipLeft});
// Scroll menu
var top = (e.pageY - wrapperOffset.top) * (scrollableHeight - wrapperHeight) / wrapperHeight - inactiveMargin;
if (top < 0){
top = 0;
}
wrapper.scrollTop(top);
});
// Setting interval helps solving perfomance problems in IE
var interval = setInterval(function(){
if (!lastTarget) return;
var currentText = tooltip.text();
if (lastTarget.nodeName == 'IMG'){
// We've attached data to a link, not image
var newText = $(lastTarget).parent().data('tooltipText');
// Show tooltip with the new text
if (currentText != newText) {
tooltip
.stop(true)
.css('opacity', 0)
.text(newText)
.animate({opacity: 1}, 1000);
}
}
}, 200);
// Hide tooltip when leaving menu
wrapper.mouseleave(function(){
lastTarget = false;
tooltip.stop(true).css('opacity', 0).text('');
});
/*
//Usage of hover event resulted in performance problems
scrollable.find('a').hover(function(){
tooltip
.stop()
.css('opacity', 0)
.text($(this).data('tooltipText'))
.animate({opacity: 1}, 1000);
}, function(){
tooltip
.stop()
.animate({opacity: 0}, 300);
});
*/
}
}
$(function(){
makeScrollable("div.sc_menu_wrapper", "div.sc_menu");
});
</script>
</head>
<body>
<div style="overflow: hidden;" class="sc_menu_wrapper">
<div style="display: block;" class="sc_menu">
</div>
<div style="display: none;" class="loading">Loading...</div><div style="opacity: 0;" class="sc_menu_tooltip"></div></div>
</body></html>
</php>
See Hotel
This code will work...
Hi i'm using this code to fetch new images from a folder to populate an slideshow.
after each cycle ajax should check content of the folder to see if any there was any
changes(pictures added or removed) then on the next cycle it should make the new changes to
the slideshow
<html>
<meta http-equiv="refresh" content="1000"/>
<head>
<title>Slideshow</title>
<style type="text/css">
#slideshow
#slideshow img { padding: 15px; border: 1px solid #ccc; background-color: #eee; }
#slide {width: 370px; height: 220px; padding: 0; margin: 0 auto; }
#myslides {
width: 370px;
height: 220px;
padding: 0;
margin: 0 auto;
}
#myslides img {
padding: 10px;
border: 1px solid rgb(100,100,100);
background-color: rgb(230,230,230);
width: 350px;
height: 200px;
top: 0;
left: 0
}
</style>
</head>
<!-- include jQuery library -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<!-- include Cycle plugin -->
<script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#slideshow').cycle({
fx: 'fade',
speed: 700,
timeout: 8000
});
});
</script>
<body>
<div id="slideshow">
</body>
</html>
<script>
$(function(){
window.onload("fetchImages()", 2);
function fetchImages() {
$.ajax({
type: "GET",
url: "load.php"
}).done(function(response){
var curImgCount = $('#slideshow img').length;
if (response.length > curImgCount) {
for (var i = curImgCount; i < response.length; i++) {
$('#slideshow').append('<img src="images/' + response[i] + '"');
}
}
});
}
});
</script>
and content of php:
<?php
function returnimages($dirname="./images") {
$pattern="([^\s]+(\.(?i)(jpg|png|gif|bmp))$)";
$files = array();
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(preg_match($pattern, $file)){ //if this file is a valid image
$files[] = $file;
}
}
closedir($handle);
}
//sort($files);
natcasesort($files);
return($files);
}
$images = returnimages();
foreach($images as $img)
{
echo json_encode($images);
}
?>
Change your PHP to:
<?php
function returnimages($dirname="./images") {
$pattern="([^\s]+(\.(?i)(jpg|png|gif|bmp))$)";
$files = array();
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(preg_match($pattern, $file)){ //if this file is a valid image
$files[] = $file;
}
}
closedir($handle);
}
//sort($files);
natcasesort($files);
return($files);
}
$images = returnimages();
echo json_encode($images);
?>
and your HTML to:
<html>
<head>
<meta http-equiv="refresh" content="1000"/>
<title>Slideshow</title>
<style type="text/css">
#slideshow {
position: relative;
}
#slideshow,
#slideshow img {
position: absolute;
top: 0px;
left: 0px;
padding: 15px;
border: 1px solid #ccc;
background-color: #eee;
}
#slide {
width: 370px;
height: 220px;
padding: 0;
margin: 0 auto;
}
#myslides {
width: 370px;
height: 220px;
padding: 0;
margin: 0 auto;
}
#myslides img {
padding: 10px;
border: 1px solid rgb(100,100,100);
background-color: rgb(230,230,230);
width: 350px;
height: 200px;
top: 0;
left: 0
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script>
<script type="text/javascript">
function loadSlides() {
$.ajax({
type: "GET",
url: "load.php"
}).done(function(response) {
var temp_images = eval("(" + response + ")");
for(ti in temp_images)
{
//alert(temp_images[ti]);
$('#slideshow').append('<img src="images/' + temp_images[ti] + '" alt="">');
}
startSlideshow();
});
}
function startSlideshow()
{
$('#slideshow').cycle({
fx: 'fade',
speed: 700,
timeout: 800
});
}
$(document).ready(function(){
loadSlides();
});
</script>
</head>
<body>
<div id="slideshow" />
</body>
</html>
I'm testing this code and it works fine but why the refresh meta tag? Isn't the point of AJAX to prevent this from happening and make it dynamic? Also, the biggest problem is that you need to set a meta refresh time that is not too long such that images don't take too long to reflect when added or deleted and not too short to prevent some images from showing at all (inevitable at some point).