Salve a tutti!
Con JCarousel carico uno script in php che popola un array che contiene le url delle immagini. Avendo bisogno di associare un link ad ogni immagine, come potrei fare?
Questo è il mio codice:
ecco il codice javascript/html:codice://la pagina php $query = "SELECT denominazione, image FROM users"; $result = mysql_query($query, $conn); $images[]=array(); $urls[]=array(); $i=0; while ($row=mysql_fetch_array($result)) { $images[$i]=$row[1]; //qui ci va l'url dell'immagine $urls[$i]=$row[0]; //qui ci va la denominazione $i++; } // Array indexes are 0-based, jCarousel positions are 1-based. $first = max(0, intval($_GET['first']) - 1); $last = max($first + 1, intval($_GET['last']) - 1); $length = $last - $first + 1; $total = count($images); $selected = array_slice($images, $first, $length); // --- header('Content-Type: text/xml'); echo '<data>'; // Return total number of images so the callback // can set the size of the carousel. echo ' <total>' . $total . '</total>'; foreach ($selected as $img) { echo ' <image>' . $img . '</image>'; } echo '</data>';
Insomma: si tratta di passare dalla pagina php oltre all'url anche la denominazione. Potrei passare i dati via xml, ok, ma come li interpreto poi in javascript?codice:<script type="text/javascript"> function mycarousel_itemLoadCallback(carousel, state) { // Check if the requested items already exist if (carousel.has(carousel.first, carousel.last)) { return; } jQuery.get( 'aj_car.php', { first: carousel.first, last: carousel.last }, function(xml) { mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml); }, 'xml' ); }; function mycarousel_itemAddCallback(carousel, first, last, xml) { // Set the size of the carousel carousel.size(parseInt(jQuery('total', xml).text())); jQuery('image', xml).each(function(i) { carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text())); }); }; /** * Item html creation helper. */ function mycarousel_getItemHTML(url) { return '[img]' + url + '[/img]'; ///////////////////////////////////////////////////////////qui avrei bisogno di una cosa tipo //// return'<a href=link.php?denominazione=denominazione>[img]' + url + '[/img]</a> ///////////////////////////////////////////////////////////////////////////////// }; jQuery(document).ready(function() { jQuery('#mycarousel').jcarousel({ // Uncomment the following option if you want items // which are outside the visible range to be removed // from the DOM. // Useful for carousels with MANY items. itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }}, itemLoadCallback: mycarousel_itemLoadCallback }); }); </script>
Spero di essere stato chiaro...
Grazie!

Rispondi quotando