1.类似下面的菜单栏,用JQuery实现
<li class="ct_li">
珠宝玉器
<ul class='mt'>
<li>翡翠</li>
<li>玉石</li>
<li>宝石</li>
<li>水晶</li>
<li>玛瑙</li>
<li>珍珠</li>
</ul>
</li>
<script>
var $li=$('.ct_li');
$li.on('mouseenter', function(){
$(this).find('.mt').show();
// 或者
// $(this).find('.child-panel').css('display', 'block');
//或者
//$(this).addClass('hover');
})
$li.on('mouseleave', function(){
$(this).find('.mt').hide();
// 或者
// $(this).find('.child-panel').css('display', 'none');
//或者
//$(this).removeClass('hover');
})
</script>
菜单选择缩略图:
<script type="text/javascript" src='http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js'>
</script>
<style>
*{margin:0;padding:0;}
.ul li{
list-style-type:none;
}
.ul li{
padding:5px;
float:left;
border:1px solid #ccc;
}
.ul{
display:block;
margin:0px;
padding:0xp;
}
.clearfix:before{
content:'';
display: block;
clear: both;
}
.clearfix:after{
content:'';
display: block;
clear: both;
}
.displaynone{
display:none;
}
.displayblock{
display:block;
}
.backgroundcolor{
opacity: 0.5;
}
.frame .wrap{
width:730px;
border:1px solid #ccc;
}
.square_red{
width:200px;
height:200px;
border:1px solid #ccc;
margin:20px;
float:left;
background-color:red;
}
.square_yellow{
width:200px;
height:200px;
border:1px solid #ccc;
margin:20px;
float:left;
background-color:yellow;
}
.square_blue{
width:200px;
height:200px;
border:1px solid #ccc;
margin:20px;
float:left;
background-color:blue;
}
.frame .button{
display:none;
width:70px;
height:25px;
line-height:25px;
padding-left:5px;
margin:85px auto;
border:1px solid #ccc;
border-radius:10px;
text-decoration:none;
color:#66ffcc;
}
</style>
<body>
<ul class='ul clearfix'>
<li>红色</li>
<li>黄色</li>
<li>蓝色</li>
</ul>
<div class='frame clearfix'>
<div class='wrap clearfix'>
<div class='square_red'>
<a href='#' class='button' >立即抢购</a>
</div>
<div class='square_red'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_red'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_red'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_red'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_red'>
<a href='#' class='button'>立即抢购</a>
</div>
</div>
<div class='wrap displaynone clearfix'>
<div class='square_yellow'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_yellow'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_yellow'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_yellow'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_yellow'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_yellow'>
<a href='#' class='button'>立即抢购</a>
</div>
</div>
<div class='wrap displaynone clearfix'>
<div class='square_blue'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_blue'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_blue'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_blue'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_blue'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_blue'>
<a href='#' class='button'>立即抢购</a>
</div>
</div>
</div>
<script >
var $ul=$('.ul'),
$wrap=$('.frame .wrap'),
$div=$('.wrap div');
$ul.on('click', 'li', function(){
$wrap.eq($li.index(this)).siblings().addClass('displaynone');
$wrap.eq($li.index(this)).removeClass('displaynone');
})
$div.on('mouseenter', function(){
$(this).addClass('backgroundcolor');
$(this).find('.button').css('display','block');
})
$div.on('mouseleave', function(){
$(this).removeClass('backgroundcolor');
$(this).find('.button').css('display','none');
})
</script>
添加节点:
<script type="text/javascript" src='http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js'>
</script>
<style>
*{margin:0;padding:0;}
.clearfix:before{
content:'';
display: block;
clear: both;
}
.clearfix:after{
content:'';
display: block;
clear: both;
}
.displaynone{
display:none;
}
.displayblock{
display:block;
}
.backgroundcolor{
opacity: 0.5;
}
.frame .wrap{
width:730px;
}
.square_red{
width:200px;
height:200px;
border:1px solid #ccc;
margin:20px;
float:left;
background-color:red;
}
.square_yellow{
width:200px;
height:200px;
border:1px solid #ccc;
margin:20px;
float:left;
background-color:yellow;
}
.square_blue{
width:200px;
height:200px;
border:1px solid #ccc;
margin:20px;
float:left;
background-color:blue;
}
.frame .button{
display:none;
width:70px;
height:25px;
line-height:25px;
padding-left:5px;
margin:85px auto;
border:1px solid #ccc;
border-radius:10px;
text-decoration:none;
color:#66ffcc;
}
.add{
border:1px solid #ccc;
border-radius:10px;
text-decoration:none;
padding: 10px;
margin-left: 20px;
margin-top: 30px;
float: left;
}
</style>
<body>
<div class='frame clearfix'>
<div class='wrap clearfix'>
<div class='square_red'>
<a href='#' class='button' >立即抢购</a>
</div>
<div class='square_red'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_red'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_red'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_red'>
<a href='#' class='button'>立即抢购</a>
</div>
<div class='square_red'>
<a href='#' class='button'>立即抢购</a>
</div>
</div>
</div>
<a href='#' class='add' >立即抢购</a>
<script >
var products = [
{
img: 'http://img10.360buyimg.com/N3/jfs/t2242/92/1446546284/374195/9196ac66/56af0958N1a723458.jpg',
name: '珂兰 黄金手 猴哥款',
price: '¥405.00'
},{
img: 'http://img10.360buyimg.com/N3/jfs/t2242/92/1446546284/374195/9196ac66/56af0958N1a723458.jpg',
name: '珂兰 黄金转运珠 猴哥款',
price: '¥100.00'
},{
img: 'http://img10.360buyimg.com/N3/jfs/t2242/92/1446546284/374195/9196ac66/56af0958N1a723458.jpg',
name: '珂兰 黄金手链 3D猴哥款',
price: '¥45.00'
}
];
function addnode(prod){
var node='';
node="<div class='square_red'>"+prod.name+"<a href='#' class='button' >立即抢购</a>"+prod.price+"</div>";
return node
}
var $wrap=$('.wrap'),
$add=$('.add');
$wrap.on('mouseenter','div' , function(){
$(this).addClass('backgroundcolor');
$(this).find('.button').css('display','block');
})
$wrap.on('mouseleave','div' , function(){
$(this).removeClass('backgroundcolor');
$(this).find('.button').css('display','none');
})
$add.on('click', function(){
$.each(products, function(i, prod){
var addhtml=addnode(prod);
$wrap.append(addhtml);
})
})
</script>