...

View Full Version : Change image and text simultaneously



PSampras
11-20-2010, 02:58 PM
Hi,
i developed a website with php.
Using cms, users can upload an image and a textual description of this image.

I use jquery to change automatically that images.
This is the code:


$this->LoadRecords();
if(count($this->_records) > 0) {//visualizzazione del focus
$this->makeGroups(); //faccio i gruppi dell'immagine a seconda della cateogira del prodotto
?>
<script type="text/javascript">
<?
$uploadDir = UploadDir();
foreach ($this->groups as $code => $group){ //
echo "array_img_$code = Array();\n";
$jj=0;
foreach ($group as $idx => $r){
foreach($r->images as $img){
$src = $uploadDir.$img->fields["dir_ima"] . "/" . $img->fields["file_ima"];
}
if ($src !="") { //trovata img
?>
array_img_<?=$code?>[<?=$jj?>] = '<?=$src?>';
<?
$jj++; //aggiorno l'index. Non posso ussare pił $idx perchč puo succedere di avere un prodotto con la spunta di homepage ma senza img con questo type
}
$src = ""; //svuoto e ricomincio il ciclo
}
}
?>
</script>
<noscript>
<p>javascript non abilitato, per visualizzare i prodotti si consiglia di visitare la galleria</p>
</noscript>
<?
$i = 0;
foreach ($this->groups as $code => $group){
$src="";
foreach ($group as $r){
foreach($r->images as $img){
$src = $uploadDir.$img->fields["dir_ima"] . "/" . $img->fields["file_ima"];
$url = $r->fields["url_dat"];
break;
}
if ($src != "") break; //trovata per questo group
}
if ($src != ""){
?>
<div id="focusBox">
<div id="focus_5">
<?
if($url != '') {
?>
<a href="<?=$url?>" title="vai">
<?
}
?>
<img width="444" height="210" alt="immagine" src="<?=$src?>" />
<?
if($url != '') {
?>
</a>
<?
}
?>
</div> <!-- end focus -->
<div id="rightFocus">
<div class="textFocus">
<div class="titoloFocus">
<?
if($url != '') {
?>
<a title="<?=$r->fields["title_dat"]?>" href="<?=$url?>"><?=$r->fields["title_dat"]?></a>
<?
} else {
?>
<a title="<?=$r->fields["title_dat"]?>"><?=$r->fields["title_dat"]?></a>
<?
}
?>
</div><!-- end titoloFocus -->
<div class="desFocus"><?=$r->fields["abstract_dat"]?></div>
</div>
</div><!-- end rightFocus -->
</div> <!-- end focusBox -->
<?
}
}
} else {
//se non ci sono cms, visualizzo un messaggio d'errore
$this->ShowNoCmsError();
}
$this->Scripts_focus();
}

function makeGroups(){
foreach($this->getCategories() as $cod) //inizializzo matrix
$this->groups[$cod] = array();

foreach($this->_records as $idx => $r) { //compilo a seconda della categoria
array_push($this->groups[$r->fields["sec_dat"]], $r);
}
}


function Scripts_focus() {
?>
<script type="text/javascript">
categories = Array();
<?
$this->categories = $this->getCategories();
for ($i=0; $i<count($this->categories); $i++){
echo "categories[".$i."]='".$this->categories[$i]."';\n";
echo "var numvisible_".$this->categories[$i]." = 0;\n";
}
?>
function changeImage(categoria){
var d = document;
var aux = parseInt(eval('numvisible_'+categoria));
var array_img = eval('d.MM_'+categoria);

if (array_img.length>1){
var img_index =(aux+1)%array_img.length;
var div = $('#focus_'+categoria);
var img =$('#focus_'+categoria+' img');

var control = "url('"+ array_img[img_index].src+"')";
$(div).css('background-image', control);
$(img).animate({opacity:0.01},3000,function(){
this.src = array_img[img_index].src;
$(img).animate({opacity:1},1000);
// $(img).css("opacity",1);
});

eval ("numvisible_"+categoria+"=img_index");
}
}

function Init_Focus(){
var j;
for (j=0; j<categories.length; j++) {
var categoria = categories[j];
var array_img = eval('array_img_'+categoria);
MM_preloadImages(array_img, categoria);
setInterval("changeImage("+categoria+")",5000);
}
}

function MM_preloadImages(img, categoria) { //v3.0
var d=document;

eval("d.MM_"+categoria+"= new Array()");
var i,j=0;
var a = img;
for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){
eval("d.MM_"+categoria+"[j]=new Image");
eval("d.MM_"+categoria+"[j++].src=a[i]");
}
}

Init_Focus();

</script>
<?

} //end ScriptFocus


What i have to add to change image and text (it's in div class="desFocus") simultaneously?

Thank you in advance.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum