I am trying to change the color of <li>
elements when they are between 30% and 60% of the viewport.
So I have this grid of elements stacking side by side like this:
I ran into few plugins like Waypoints, Viewport Checker and few others but nothing good.
Any idea?
I am using a pretty simple structure :
JSFIDDLE
HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<meta name="author" content="">
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/styles.css">
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="js/main.js"></script>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>
CSS:
ul {
margin: auto;
}
ul li {
width: 300px;
height: 200px;
background: #f5f5f5;
float: left;
margin: 10px;
}
ul li.middleviewport{
background:red;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…