1.類似下面的菜單欄绽乔,用JQuery實現(xiàn)
<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>藍(lán)色</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>
添加節(jié)點:
<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: '珂蘭 黃金轉(zhuǎn)運珠 猴哥款',
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>