How to put a vertical scroll bar on a dijit menu
I would like to create a dijit
menu that has a vertical
scroll bar.
I've tried doing this:
pMenu = new dijit.Men开发者_如何学Gou({
templateString: '<div style="height: 75px; overflow-y: auto; overflow-x:hidden">' + dojo.cache("dijit", "templates/Menu.html") + '</div>'
});
When I do that, the vertical scroll bar appears but the width is to small (it didn't expand to account for the scroll bars width).
Is there a better way to do this? I essentially want a maxHeight
attribute on dijit.menu
This is just an idea to show you how you could detect element scrollbar presence:
<html>
<head>
<title>Detect Scrollbars Presence</title>
<script type="text/javascript">
function verticalScrollBarExists(id)
{
var element = document.getElementById(id);
oldScrollTop = element.scrollTop;
element.scrollTop = 1;
if (element.scrollTop > 0)
{
element.scrollTop = oldScrollTop;
document.getElementById('scrollStatus').innerHTML = 'scroll bar visible';
// increase element width
element.style.width = '310px';
}
else
{
document.getElementById('scrollStatus').innerHTML = 'scroll bar not visible';
// restore element width
element.style.width = '300px';
}
}
function add()
{
var element = document.getElementById('testElement');
element.innerHTML = element.innerHTML + ' Stuff';
}
function remove()
{
var element = document.getElementById('testElement');
element.innerHTML = element.innerHTML.substring(0, element.innerHTML.length - 6);
}
window.onload = function()
{
setInterval('verticalScrollBarExists("testElement")', 500);
};
</script>
<style type="text/css">
#testElement
{
width: 300px;
height: 40px;
background-color: blue;
color: white;
overflow: auto;
}
</style>
</head>
<body>
<div id="testElement">Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff Stuff</div>
<div id="scrollStatus">Uninitialised</div>
<input type="button" onclick="add()" value="Add" />
<input type="button" onclick="remove()" value="Remove" />
</body>
</html>
精彩评论