创建一个打开/关闭图层的页面

时间:2013-12-12 18:31:07

标签: html asp.net css layer

我正在尝试创建一个包含图层打开和关闭选项的页面。

有谁知道如何做这种页面?

请告诉我, 感谢

1 个答案:

答案 0 :(得分:1)

这是 FIDDLE

<button class="on">Show All</button>
<button class="off">Hide All</button>
<button data-rel="one">One</button>
<button data-rel="two">Two</button>
<button data-rel="three">Three</button>

<div class="one layer"></div>
<div class="two layer"></div>
<div class="three layer"></div>

div {
  position: absolute;
  width: 500px;
  height: 500px;
  top: 100px;
  left: 50%;
  margin-left: -250px;;
  opacity: 0.3;
}
button {
  width: 75px;
  margin-right: 15px;
}
.one {
  background: url(image1.png) 110px 0 no-repeat;
  background-size: 40px 40px;
}
.two {
  background: url(image2.png) 250px 150px no-repeat;
  background-size: 60px 60px;
}
.three {
  background: url(image3.png) 410px 310px no-repeat;
  background-size: 80px 80px;
}

$(function() {

  $('button').click(function() {

    var el = $('.'+$(this).data('rel'));

    if(el.css('opacity') === '1') {
       el.stop().animate({ opacity: '0.3' }, 300, 'linear');
    }
    else {
       el.stop().animate({ opacity: '1' }, 300, 'linear');
    }

  });

  $('.on').click(function() {
    $('.layer').stop().animate({ opacity: '1' }, 300, 'linear');    
  });

  $('.off').click(function() {
    $('.layer').stop().animate({ opacity: '0.3' }, 300, 'linear');    
  });

});