I'm trying to create a custom div scroller. I got it working, but it's still a little rough around the edges. Please take a look..
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
#content {
margin-top: 100px;
height: 500px;
width: 500px;
overflow: hidden;
border: solid 1px red;
}
#scr {
height: 100px;
width: 100px;
border: solid 1px black;
background-color: #26a0eb;
z-index: 3;
opacity: 0;
filter: alpha(opacity = 0);
}
#content:hover #scr {
opacity: 0.1;
filter: alpha(opacity = 10);
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="content">
<div id="scr">
</div>
<div id="container">
<script type="text/javascript">
var strContent = '';
for (var i = 1; i < 101; i++) {
document.writeln(i + '<br />');
}
</script>
</div>
</div>
</form>
<script type="text/javascript">
window.onload = function () {
draggable('scr');
};
var scr = null;
function draggable(id) {
var obj = document.getElementById(id);
obj.style.position = "absolute";
obj.onmousedown = function () {
scr = obj;
}
}
document.onmouseup = function (e) {
scr = null;
};
document.onmousemove = function (e) {
if (!e) e = window.event;
var y = (e.pageY) ? e.pageY : e.clientY;
if (scr == null)
return;
var c = document.getElementById('content');
if ((y >= c.offsetTop + 50) && (y < c.clientHeight + 50)) {
var pct = (scr.offsetTop - c.offsetTop) / (c.clientHeight - 50);
c.scrollTop = Math.floor(c.scrollHeight * pct);
scr.style.top = y - 50 + 'px';
}
};
</script>
</body>
</html>