有不少人想做京东商城分类效果,搜索了一下之前的帖子,发现大虾们一般都是直接下
载了京东的代码并在其基础上改。但这样会出现一个问题,就是ecshop不兼容jquery,
而这个问题解决起来比较复杂,更不好的是它会破坏ecshop的内部函数,不利于以后版
本升级。
大家不需要盲目迷信大站,其实京东商城的分类效果完全可以用纯DIV+CSS实现,不需
要jquery,甚至一句javascript都不写也能实现。
废话少说,先上图

然后上代码
第一步:在你所用的模板的css文件中加上以下代码
- .my_left_category{
- width:211px;
- font-size:12px;
- }
- .my_left_category h1{
- background-p_w_picpath:url(p_w_picpaths/spring_06.jpg);
- height:20px;
- background-repeat:no-repeat;
- font-size:14px;
- font-weight:bold;
- padding-left:15px;
- padding-top:8px;
- margin:0px;
- color:#FFF;
- .my_left_category .my_left_cat_list{
- width:209px;
- border-color:#ce2020;
- border-style:solid;
- border-width:0px 1px 1px 1px;
- line-height:13.5pt;
- .my_left_category .my_left_cat_list h2 {
- padding:3px 5px 0px 9px;
- .my_left_category .my_left_cat_list h2 a{
- color:#d6290b;
- line-height:22px;
- .my_left_category .h2_cat{
- height:26px;
- background-p_w_picpath:url(p_w_picpaths/my_menubg.gif);
- line-height:26px;
- font-weight:normal;
- color:#333333;
- position:relative;
- .my_left_category a{
- font:12px;
- text-decoration:none;
- .my_left_category a:hover{
- text-decoration:underline;
- color:#ff3333;
- .my_left_category h3{
- padding:0px;
- display:block;
- padding-left:8px;
- .my_left_category h3 span{color:#999999; width:145px; float:right;}
- .my_left_category h3 a{ line-height:26px;}
- .my_left_category .h3_cat{
- display:none;
- width:204px;
- position:absolute;
- left:184px;
- margin-top:-26px;
- cursor:auto;
- .my_left_category .shadow{
- position:inherit;
- background:url(p_w_picpaths/shadow_04.gif) left top;
- .my_left_category .shadow_border{
- width:200px;
- border:1px solid #959595; margin-top:1px;
- border-left-width:0px;
- background:url(p_w_picpaths/shadow_border.gif) no-repeat 0px 21px;
- background-color:#ffffff;
- margin-bottom:3px
- .my_left_category .shadow_border ul{margin:0; padding:0; margin-left:15px}
- .my_left_category .shadow_border ul li {
- list-style:none;
- padding-left:10px;
- background-p_w_picpath:url(p_w_picpaths/my_cat_sub_menu_dot.gif);
- background-position:0px 8px;
- float:left;
- width:75px;
- overflow:hidden;
- .my_left_category .active_cat{ z-index:99;background-position:0 -25px;cursor:pointer;}
- .my_left_category .active_cat h3 { font-weight:bold}
- .my_left_category .active_cat h3 span{ display:none;}
- .my_left_category .active_cat div{display:block;}
复制代码
第二步:模板文件夹的library/category_tree.lbi内容改为:
- <meta http-equiv="Content-Type" content="text/html; charset=gbk">
- <div class="my_left_category">
- <h1>商品分类</h1>
- <div class="my_left_cat_list">
- {assign var="pre_item_level" value=-1}
- <!--{foreach from=cat_list(0,0,false,3,false) item=cat}-->
- {if $cat.level lt 2 && $pre_item_level gt 0}
- </ul></div></div></div></div>
- {/if}
- {if $cat.level eq 0}
- <h2><a href="{$cat.url}">{$cat.name|escape:html}</a></h2>
- {elseif $cat.level eq 1}
- <div class="h2_cat" onmouseover="this.className='h2_cat active_cat'" onmouseout="this.className='h2_cat'">
- <h3><SPAN> - {$cat.cat_desc|escape:html}</SPAN><a href="{$cat.url}">{$cat.name|escape:html}</a></h3>
- <div class="h3_cat">
- <div class="shadow">
- <div class="shadow_border">
- <ul>
- {elseif $cat.level eq 2}
- <li><a href="{$cat.url}">{$cat.name|escape:html}</a></li>
- {assign var="pre_item_level" value=$cat.level}
- <!--{/foreach}-->
- {if $pre_item_level gt 0}
- </div>
第三步:把用到的图片拷贝到模板文件夹的p_w_picpaths目录
ok完成!
注:
京东的二级分类名称旁边列了2个三级分类名称(灰色),作为三级分类的提示。参考其他网友的做法,这里使用二级类的描述字段cat_desc来实现,【用程序去调取二级类下的前两个三级分类完全是化简为烦的事情。】但这个效果要修改 /includes/lib_common.php 才生效的,当然,不修改也不会出错,只是没有显示罢了。
修改方法:在/includes/lib_common.php 的cat_list函数中找到
$sql = "SELECT c.cat_id, c.cat_name,
修改为
$sql = "SELECT c.cat_id, c.cat_name, c.cat_desc,
补充一下:
在firefox等浏览器中,如果展开的部分被遮挡(由于父级容器overflow:hidden引起),在.my_left_category的样式中加上 position:absolute即可。
今天上午放出的category_tree.lbi代码有点bug,当最后一个顶级分类下面没有子类的时候,会生成一段多余的“</ul></div></div></div></div>”,把26行的</ul></div></div></div></div>改为
- </ul></div></div></div></div>
- {/if}
即可
1楼的附件和代码已更改过来,本楼之前下载的朋友请更新一下