1.菜单栏点击产生水波纹效果,代码如下:
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>原生js实现水波纹效果</title>
<style type="text/css">
.container {
width: 600px;
height: 600px;
margin: 0 auto;
text-align: center;
}
.menu {
width: 480px;
padding: 0;
margin: 40px auto;
position: relative;
}
li {
width: 160px;
height: 60px;
line-height: 60px;
font-size: 16px;
text-align: center;
float: left;
list-style: none;
background: #009999;
color: #fff;
overflow: hidden;
cursor: pointer;
box-sizing: border-box;
}
.slider {
display: block;
height: 4px;
clear: both;
background: #cc3333;
position: absolute;
left: 0;
top: 60px;
transition: all 0.5s;
}
.ripple {
width: 0;
height: 0;
border-radius: 50%;
background: rgba(255, 255, 255, 0.4);
-webkit-transform: scale(0);
-ms-transform: scale(0);
-moz-transform: scale(0);
transform: scale(0);
position: absolute;
opacity: 1;
}
.rippleEffect {
animation: rippleDrop 0.4s linear;
-webkit-animation: rippleDrop 0.4s linear;
}
@-webkit-keyframes rippleDrop {
100% {
-webkit-transform: scale(2);
-ms-transform: scale(2);
-moz-transform: scale(2);
transform: scale(2);
opacity: 0;
}
}
@keyframes rippleDrop {
100% {
-webkit-transform: scale(2);
-ms-transform: scale(2);
-moz-transform: scale(2);
transform: scale(2);
opacity: 0;
}
}
</style>
</head>
<body>
<div class="container">
<ul class="menu">
<li class="li" id="li1">首页</li>
<li class="li" id="li2">发现</li>
<li class="li" id="li3">我的</li>
<li class="slider"></li>
</ul>
</div>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
<script type="text/javascript">
window.onload = function () {
var array = $('.li');
var border = document.getElementsByClassName('slider');
$('.li').click(function (e) {
var whatTab = $(this).index();
var howFar = 160 * whatTab;
$(".slider").css({
left: howFar + "px"
});
$(".ripple").remove();
var posX = $(this).offset().left,
posY = $(this).offset().top,
buttonWidth = $(this).width(),
buttonHeight = $(this).height();
$(this).prepend("<span class='ripple'></span>");
if (buttonWidth >= buttonHeight) {
buttonHeight = buttonWidth;
} else {
buttonWidth = buttonHeight;
}
var x = e.pageX - posX - buttonWidth / 2;
var y = e.pageY - posY - buttonHeight / 2;
$(".ripple").css({
width: buttonWidth,
height: buttonHeight,
top: y + 'px',
left: x + 'px'
}).addClass("rippleEffect");
});
}
</script>
</body>
</html>