jQuery 动画图像交换

发布于 2024-09-08 05:23:57 字数 2786 浏览 5 评论 0原文

你好。又是我,又是 jQuery。

我有这样的东西: http://misiur.com/small/

当单击左侧的菜单时,然后我想改变这个图像的src,或者只是交换它。不过我想把它做成动画。图像路径取自数据库,并存储在“images”数组中(您可以使用 firebug 检查)。

谢谢

更新:

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();

}); });

顺便提一句。现在点击不起作用

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尘世孤行 2024-09-15 05:23:57

@Misiur

很抱歉,您发布的链接包含一个javascript语法错误,其写法如下

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

我认为应该是这样的

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

如果我错了(或)误导您,请原谅

@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

柠檬 2024-09-15 05:23:57

这个之类的东西?

Something like this?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文