JQ仿ebay右侧flash商品展示

开blog很久,今天第一次发表,因为本人啊实在不喜欢写文章,唉~以前语文老是不及格。

一直以来在思考,不知道学flash好还是silverlight好,结果在途中冒出了个JQ,凑用一下吧,反正我觉得未来flash或silverlight才是王道,未来……不知道是什么时候……

仿www.ebay.com简单做了个展示框,ebay用来展示商品,而我是用来展示产品,差不多吧,希望大家多多拍砖

 

先看看demo

 

为图片做准备

img.ashx
public class img : IHttpHandler {
    
static public int percent = 0;
    
public void ProcessRequest (HttpContext context) {
        
//实现延时
        int sleep = int.Parse(context.Request.QueryString["sleep"]);
        Thread.Sleep(sleep);
        
//生成图 片       
        context.Response.ContentType = "image/jpeg";
        Image image 
= Image.FromFile(context.Server.MapPath("images/2.jpg"));
        MemoryStream ms 
= new MemoryStream();
        image.Save(ms,ImageFormat.Jpeg);
        context.Response.BinaryWrite(ms.ToArray());
    }
 
    
public bool IsReusable {
        
get {
            
return false;
        }
    }

}

 

生成产品列表,并返回JSON

 

data.ashx
using System;
using System.Web;
using System.Collections.Generic;
using Newtonsoft.Json;
public class Product
ContractedBlock.gif
{
ContractedSubBlock.gif    
public int ID getset; }
ContractedSubBlock.gif    
public int ParentID getset; }
ContractedSubBlock.gif    
public string Name getset; }
ContractedSubBlock.gif    
public string ImageUrl getset; }
}

public class data : IHttpHandler
ContractedBlock.gif
{

    
public void ProcessRequest(HttpContext context)
ContractedSubBlock.gif    
{
        
//获取产品父ID
        int parentID = int.Parse(context.Request.QueryString["parentID"]);
        List
<Product> li = new List<Product>();
        Random ran 
= new Random();
        
for (int i = 1; i <= parentID; i++)
ContractedSubBlock.gif        
{
            
//随机生产图片下载延时
            int sleep = ran.Next(110* 1000;
            li.Add(
new Product
ContractedSubBlock.gif            
{
                ID 
= i,
                Name 
= "product" + i.ToString(),
                ParentID 
= parentID,
                ImageUrl 
= "img.ashx?sleep=" + sleep.ToString()
            }
);
        }

        context.Response.ContentType 
= "text/plain";
        context.Response.Write(JavaScriptConvert.SerializeObject(li));
    }


    
public bool IsReusable
ContractedSubBlock.gif    
{
        
get
ContractedSubBlock.gif        
{
            
return false;
        }

    }


}


好了,到了页面展示部分了,先看看css

 

页面css
ContractedBlock.gif    <style type="text/css">
        body
ContractedSubBlock.gif        
{}{
            font-size
: small;
        
}

        #ShowImg
ContractedSubBlock.gif        
{}{
            float
: left;
            width
: 300px;
            height
: 300px;
            line-height
: 300px;
            text-align
: center;
            vertical-align
: middle;
            font-size
: 260px;
        
}

        #ShowImg img
ContractedSubBlock.gif        
{}{
            vertical-align
: middle;
        
}

        #Navigation
ContractedSubBlock.gif        
{}{
            padding-left
: 4px;
            float
: left;
            width
: 300px;
            height
: 300px;
            overflow
: hidden;
        
}

        #Navigation ul
ContractedSubBlock.gif        
{}{
            padding
: 0px;
            margin
: 0px;
            list-style-type
: none;
        
}

        #Navigation li
ContractedSubBlock.gif        
{}{
            float
: left;
            margin
: 1px;
            width
: 70px;
            height
: 70px;
            border
: solid 1px #cccccc;
            cursor
: pointer;
            background-color
: #FFFFFF;
            overflow
: hidden;
        
}

        #Mask
ContractedSubBlock.gif        
{}{
            text-align
: center;
            position
: absolute;
            background-image
: url( 'images/load-bg.png' );
            width
: 604px;
            height
: 304px;
            left
: 2px;
            top
: 2px;
            line-height
: 304px;
        
}

        #mask img
ContractedSubBlock.gif        
{}{
            padding-top
: 150px;
        
}

        #productList a
ContractedSubBlock.gif        
{}{
            float
: left;
            width
: 60px;
        
}

    
</style>

 

页面html以及js

js
<script src="../js/jquery.js" type="text/javascript"></script>

    
<script language="javascript" type="text/javascript">
    
function getProduct(parentID){
        
var imgLoad=0;
         $(
'#Mask').fadeIn();
         $.getJSON(
'data.ashx',{parentID:parentID},function(result){
            
var content=$('#Navigation ul');
            content.empty();
            
for(var i=0;i<result.length;i++){
                content.append(
'<li><img val="'+result[i].ID+'" src="'+result[i].ImageUrl+'" alt="'+result[i].Name+'"/></li>');
            }
            
//alert(content.find('ul'));
           content.find('li').css('opacity','0.3').hover(
                
function(){
                    $(
this).css('border-color','#ff0000');
                    $(
this).stop().animate({opacity:'1'},'fast');
                },
                
function(){
                        $(
this).stop().animate({opacity:'0.3'},'fast',function(){$(this).css('border-color','#cccccc');});
                }
            );
            
            content.find(
'img').each(function(){
                
this.onload=function(){
                    imgLoad
++;
                    
//alert(imgLoad);
                    if(imgLoad==parentID){
                        $(
'#Mask').fadeOut('slow');
                    }
                }
            });
        });
    }
    $(
function(){
        
var isSomeoneClick=false;
        $(
'#Mask').css('opacity','0.3');
        $(
'#ShowImg').css('opacity','0');
        getProduct(
5);
        $(
'#productList a').click(function(){
             getProduct($(
this).attr('pid'));
        });
    });
    
</script>

 

html
    <div>
        
<div style="width: 604px; height: 304px; border: solid #cccccc 1px; padding: 2px;
            position: relative
">
            
<div id="ShowImg">
                
<img src="" border="0" /></div>
            
<div id="Navigation">
                
<ul>
                
</ul>
            </div>
            <div id="Mask">
                
<img src="images/indicator_web20_working.gif" />
            </div>
        </div>
    </div>
    <div id="productList">
        
<a href="#" pid="5">产品5</a> <a href="#"  pid="7">产品7</a> <a href="#" pid="11">产品11</a>
        <a href="#" pid="16">产品16</a>
    </div>

 

 

转载于:https://www.cnblogs.com/Dreaming/archive/2008/08/01/1257902.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值