views:

37

answers:

3

Howdy. It's me again, and It's jQuery again.

I have somthing like that: http://misiur.com/small/

When this menu on left is clicked, then I want to change src of this image, or just swap it. However I want to make it animated. Images paths are taken from DB, and stored in "images" array (You can check that with firebug).

thanks

Update:

HTML ()+PHP:

<div id="content_menu">
<ul>
<?php 
$q = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."prodcat");                                  $c = 1;                                     $id = 1;
foreach($q as $q)   
{
echo '<li class="ml'.$c.'">
<a id="e'.$id.'" href="cat/'.$q->id.'">'.$q->name.'</a>
<img src="images/split.png" alt="" />
</li>';
$id++;
$c++;
if($c == 8)
{
    $c = 1;
}
}
</ul>
</div>
<div id="product_display">
      <div id="product">
                <img id="changer" src="images/ex.jpg" style="background-image: url('images/products/cat/2.png');" alt="Przykład" />
                <div id="pmore"><a href="#">Więcej</a></div>
      </div>
</div>

JS:

<script type="text/javascript">
$(window).bind('load', function ()
{
var images = new Array();
<?php 
$q = $wpdb->get_results("SELECT id, image FROM ".$wpdb->prefix."prodcat");
foreach($q as $q)
{
echo "images[".($q->id-1)."] = 'images/products/cat/".$q->image."';\r\n";
}
?>
$('#content_menu a').click(function(e){
e.preventDefault(); 
var id = this.id.substr(1) % 7;
var i = this.id.substr(1);
$('#changer').css('background-image', images[i]);
switch(id)
{
    case 2:
        $('#product').animate({ backgroundColor: '#FFCD00' }, 500);
        $('#pmore').animate({ backgroundColor: '#FFCD00' }, 500);
    break;
    case 3:
        $('#product').animate({ backgroundColor: '#F7A604' }, 500);
        $('#pmore').animate({ backgroundColor: '#F7A604' }, 500);
    break;
    case 4:
        $('#product').animate({ backgroundColor: '#9A05E8' }, 500);
        $('#pmore').animate({ backgroundColor: '#9A05E8' }, 500);
    break;
    case 5:
        $('#product').animate({ backgroundColor: '#096EE3' }, 500);
        $('#pmore').animate({ backgroundColor: '#096EE3' }, 500);
        break;
    case 6:
        $('#product').animate({ backgroundColor: '#24A205' }, 500);
        $('#pmore').animate({ backgroundColor: '#24A205' }, 500);
    break;
    case 0:
        $('#product').animate({ backgroundColor: '#D41E0C' }, 500);
        $('#pmore').animate({ backgroundColor: '#D41E0C' }, 500);
    break;
    case 1:
        default:
        $('#product').animate({ backgroundColor: '#44B2EE' }, 500);
        $('#pmore').animate({ backgroundColor: '#44B2EE' }, 500);
}
$('#changer').cross();

}); });

BTW. now click doesn't work

A: 

Something like this?

Andy Robinson
Well, I've tried, however I've got new idea about it. I'll tell if I discovered anything.
Misiur
A: 

Maybe this

Neb
+1  A: 

@Misiur

sorry to say , the link which you posted contains a javascript syntatic error , it is written as follows

var images = new Array();
 images[] = 'images/products/cat/1.jpg';
 images[] = 'images/products/cat/2.png'; 

I Think it should be some thing like this

var images = new Array();
 images[0] = 'images/products/cat/1.jpg';
 images[1] = 'images/products/cat/2.png';

Excuse me if I'm wrong (or) misleading you

Ninja Dude
PHP Habit :D Now better
Misiur