代码之家  ›  专栏  ›  技术社区  ›  Misiur

jQuery动画图像交换

  •  0
  • Misiur  · 技术社区  · 15 年前

    你好。又是我,又是jQuery。

    我有这样一件事: http://misiur.com/small/

    谢谢

    更新:

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

    }); });

    2 回复  |  直到 15 年前
        1
  •  0
  •   Andy Robinson    15 年前
        2
  •  1
  •   user372551 user372551    15 年前

    @米苏尔

    很抱歉,您发布的链接包含一个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';