以下是 js多个产品对比插件特效代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js多个产品对比插件</title>
<link href="css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery.1.4.2-min.js"></script>
</head>
<body>
<div class="headeline"></div>
<!--演示内容开始-->
<script type="text/javascript">
var isopen=false;
//关闭div层
function hidediv(){
$('div.floatdiv:visible').hide();
isopen=false;
}
//显示div层
function showdiv(){
$('div.floatdiv:hidden').show();
isopen=true;
}
//点击图标删除此行
function delplan(obj){
var parent=obj.parentNode;
var id=parent.id;
parent.parentNode.removeChild(parent);
//去除选中的
var checkid="planid"+id.substr(2,id.length);
document.getElementById(checkid).checked=false;
}
//checkbox的点击
function actionplan(obj){
var planid=obj.parentNode.parentNode.getAttribute("planid");
var planname=obj.parentNode.parentNode.getAttribute("planname");
if(isopen==false){
showdiv();
}
addplan(planid,planname);
}
//选中一个元素添加到对比
function addplan(planid,planname){
if(document.getElementById("planid"+planid).checked){
if($("#selectedplan li").length>3){
document.getElementById("planid"+planid).checked=false;
alert("最多四个元素");
return false;
}
$("#selectedplan").append("<li style='cursor:pointer;' id=li"+planid+"><img src=images/icon_6.gif onclick=delplan(this) style=cursor:pointer;></img>"+planname+"</li>");
}else{
var obj=document.getElementById("li"+planid);
obj.parentNode.removeChild(obj);
}
}
</script>
<div class="demo">
<table cellpadding="0" cellspacing="0" width="100%">
<thead>
<tr>
<th>代码</th><th>名称</th><th>涨跌</th><th>涨幅</th><th>对比</th>
</tr>
</thead>
<tbody>
<tr planid="001" planname="大摩基础">
<td>001</td>
<td> 大摩基础</td>
<td>-0.0088</td>
<td>-0.45%</td>
<td><input type="checkbox" id="planid001" onclick="actionplan(this)" name="compareplan" value="001" /></td>
</tr>
<tr planid="002" planname="华夏全球">
<td>002</td>
<td> 华夏全球</td>
<td>-0.0088</td>
<td>-0.45%</td>
<td><input type="checkbox" id="planid002" onclick="actionplan(this)" name="compareplan" value="002" /></td>
</tr>
<tr planid="003" planname="华夏复兴">
<td>003</td>
<td> 华夏复兴</td>
<td>-0.0088</td>
<td>-0.45%</td>
<td><input type="checkbox" id="planid003" onclick="actionplan(this)" name="compareplan" value="003" /></td>
</tr>
<tr planid="004" planname="华夏成长">
<td>004</td>
<td> 华夏成长</td>
<td>-0.0088</td>
<td>-0.45%</td>
<td><input type="checkbox" id="planid004" onclick="actionplan(this)" name="compareplan" value="004" /></td>
</tr>
<tr planid="005" planname="华夏大盘">
<td>005</td>
<td> 华夏大盘</td>
<td>-0.0088</td>
<td>-0.45%</td>
<td><input type="checkbox" id="planid005" onclick="actionplan(this)" name="compareplan" value="005" /></td>
</tr>
</tbody>
</table>
</div>
<style type="text/css">
*{margin:0;padding:0;list-style-type:none;}
a,img{border:0;}
table{empty-cells:show;border-collapse:collapse;border-spacing:0;}
.demo{width:680px;margin:40px auto 0 auto;}
.demo table th{background:#eeeeee;}
.demo table th,.demo table td{border:solid 1px #ddd;text-align:center;padding:10px 0;font-size:12px;line-height:20px;}
/* floatdiv */
.floatdiv{position:fixed;top:240px;right:0;z-index:9999;width:100%;}
*html,*html body /* 修正IE6振动bug */{background-image:url(about:blank);background-attachment:fixed;}
*html .floatdiv{position:absolute;top:expression(eval(document.documentElement.scrollTop));}
.floatdiv{background:url(images/dialog_bg.gif) no-repeat;width:160px;height:208px;overflow:hidden;}
.floatdiv h5{color:#fff;font-size:12px;height:30px;line-height:30px;overflow:hidden;padding:0 0 0 5px;}
.floatdiv h5 a{float:right;margin:5px 5px 0 0;display:inline;}
.floatdiv ul{height:130px;overflow:hidden;padding:10px 10px 5px 20px;}
.floatdiv ul li{height:24px;line-height:24px;font-size:12px;}
.floatdiv ul li img{margin:0 5px 0 0;}
</style>
<div class="floatdiv">
<h5>您已经选择的基金 <a style="cursor:pointer;" onClick="hidediv()"><img src="images/icon_7.gif" alt="" /></a></h5>
<ul id="selectedplan"></ul>
<p align="center"><a href="javascript:void(0);" onClick="document.getElementById('compareplan').submit();"><img src="images/btn_7.gif" alt="" /></a></p>
</div><!--end floatdiv-->
<div style="height:1000px;"></div>
<!--演示内容结束-->
</body>
</html>
CSS代码(style.css):
@charset "utf-8";/* reset */
*{margin:0;padding:0;list-style-type:none;}
a{blr:expression(this.onFocus=this.blur())}
/*去掉a标签的虚线框,避免出现奇怪的选中区域*/
:focus{outline:0;}
label{cursor:pointer;}
img{vertical-align:middle;}
table{empty-cells:show;border-collapse:collapse;border-spacing:0;}
h1{font-size:16px;}
h2,h3,h4{font-size:14px;}
h5,h6{font-size:12px;}
abbr,acronym{border:0;font-variant:normal}
address,caption,cite,code,dfn,em,th,var,optgroup{font-style:normal;font-weight:normal}
input,button,textarea,select,optgroup,option{font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit}
input,button,textarea,select{*font-size:100%}
a,img{border:0;}
a,a:visited{color:#5e5e5e;text-decoration:none;}
a:hover{color:#4183C4;text-decoration:underline;}
.clear{display:block;overflow:hidden;clear:both;height:0;line-height:0;font-size:0;}
.clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden;}
.clearfix{display:inline-table;}
/* Hides from IE-mac \*/
*html .clearfix{height:1%;}
.clearfix{display:block;}
/* End hide from IE-mac */
*+html .clearfix{min-height:1%;}
body{font:12px/180% Arial,Lucida,Verdana,"宋体",Helvetica,sans-serif;color:#333;background:#fff;}
/* shortcut */
.shortcut{position:fixed;top:0;left:0;z-index:9999;width:100%;}
*html,*html body /* 修正IE6振动bug */
{background-image:url(about:blank);background-attachment:fixed;}
*html .shortcut{position:absolute;top:expression(eval(document.documentElement.scrollTop));}
.shortcut{height:28px;line-height:28px;font-size:12px;background:#EEEEEE;text-transform:uppercase;box-shadow:1px 0px 2px rgba(0,0,0,0.2);border-bottom:1px solid #DDDDDD;}
.shortcut h1{font-size:14px;font-family:"微软雅黑","宋体";}
.shortcut a,.shortcut h1{padding:0px 10px;letter-spacing:1px;color:#333;text-shadow:0px 1px 1px #fff;display:block;float:left;}
.shortcut a:hover{background:#fff;}
.shortcut span.right{float:right;}
.shortcut span.right a{float:left;display:block;color:#ff6600;font-weight:800;}
.headeline{height:40px;overflow:hidden;}
.adv960x90{width:960px;height:90px;overflow:hidden;border:solid 1px #E6E6E6;margin:40px auto 0 auto;}
.adv728x90{width:728px;height:90px;overflow:hidden;border:solid 1px #E6E6E6;margin:0 auto;}