non-stretching background?
I'm trying to make a nav menu. I've not done much jquery before, but have managed to get this far.
I expected the default behavior to not stretch the background image, but it does.
Is there a css3 tag or some other approach I can use to prevent the background from stretching when I change the height of the div?
Here's my menu so far...
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title></title>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
- <script type="text/javascript">
- var lastY = 0;
- var direction = '';
- $(document).ready(function()
- {
- $('body').mousemove(
- function(e){
- if (e.pageY < lastY) direction = 'up';
- else direction = 'down';
- lastY = e.pageY;
-
- if (direction == 'down')
- {
- $('.box').hover(
- function(){
- $(this).find('.layer').stop().animate({'height': '30px'}, 'fast');
- $(this).find('.layer').css('bottom', '').css('top', '0');
- },
- function(){
- $(this).find('.layer').stop().animate({'height': '0px'}, 'fast');
- $(this).find('.layer').css('top', '').css('bottom', '0');
- });
- }
-
- if (direction == 'up')
- {
- $('.box').hover(
- function(){
- $(this).find('.layer').stop().animate({'height': '30px'}, 'fast');
- $(this).find('.layer').css('top', '').css('bottom', '0');
- },
- function(){
- $(this).find('.layer').stop().animate({'height': '0px'}, 'fast');
- $(this).find('.layer').css('bottom', '').css('top', '0');
- });
- }
- });
- });
- </script>
- <style>
- .box {
- border: 1px solid #07A;
- height: 30px;
- width: 150px;
- position: relative;
- }
- .layer {
- background: #09C url(../images/darkbluefill.png);
- background: url(http://blog.pixelingene.com/images/2008-09-23-quick-tip-to-get-a-striped-background/image4.png);
- height: 0px;
- width: 150px;
- position: absolute;
- left: 0;
- }
- </style>
- <body>
- <div class="box">
- <div class="layer"></div>
- </div>
- <div class="box">
- <div class="layer"></div>
- </div>
- <div class="box">
- <div class="layer"></div>
- </div>
- <div class="box">
- <div class="layer"></div>
- </div>
- <div class="box">
- <div class="layer"></div>
- </div>
- <div class="box">
- <div class="layer"></div>
- </div>
- </body>
- </html>