jQuery 动画图像交换
你好。又是我,又是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@Misiur
很抱歉,您发布的链接包含一个javascript语法错误,其写法如下
我认为应该是这样的
如果我错了(或)误导您,请原谅
@Misiur
sorry to say , the link which you posted contains a javascript syntatic error , it is written as follows
I Think it should be some thing like this
Excuse me if I'm wrong (or) misleading you
像这个之类的东西?
Something like this?