1

the following code i have tried in fiddle but when i actually get it on my desktop it seems not even working. the images are tried to be overlayed on main image using javascript. i guess i am going somewhere wrong in referencing. a little help will be appreciated.

code:

  <html>
  <head>
    <style>
        div {
            position:absolute;   
        }

        #main {   
            width:256px;
            height:256px;
        }

        #overlay {
            position:absolute;
            height:100px;
            width:100px;
            top:0;
            left:0; 
            display:none;
        }

        .overly {
            position:absolute;
            height:100px;
            width:100px;
            bottom:0;
            right:0; 
            display:none;    
        }
    </style>
    <script>
        $(document).ready(function() {
            $("#main").mouseenter(function() {
                $("#overlay").show();
            });
            $("#main").mouseleave(function() {
                $("#overlay").hide();
            });
        });
        $(document).ready(function() {
            $("#main").mouseenter(function() {
                $("#overly").show();
            });
            $("#main").mouseleave(function() {
                $("#overly").hide();
            });
        });
    </script>
</head>
<body style="margin:0px; padding-top:0px">
    <div>
        <a href="">
            <img id="main" src="image/productold.JPG" />
            <img id="overlay"  src="image/over1.jpg"/>
            <img class="overly" src="image/over2.jpg"/>
        </a>
    </div>
</body>
</html>
3
  • What do you need exactly? Commented Nov 4, 2013 at 9:08
  • Why do you have twice the same code document.ready(...? Commented Nov 4, 2013 at 9:22
  • i need it to display the info for an each image in an image gallery. Commented Nov 4, 2013 at 17:57

1 Answer 1

2

Try adding z-index properties to the styling of the two divs. That should allow you to put one on top of the other. For example:

  #main {   
            width:256px;
            height:256px;
            z-index: 0;
        }

        #overlay {
            position:absolute;
            height:100px;
            width:100px;
            top:0;
            left:0; 
            display:none;
            z-index: 1;
        }

        .overly {
            position:absolute;
            height:100px;
            width:100px;
            bottom:0;
            right:0; 
            display:none;
            z-index: 2;    
        }

For more information on this property, see the W3Schools page on the Z-Index property here.

Sign up to request clarification or add additional context in comments.

2 Comments

if i am trying to implement the above script for a gallery of images then the z-index specified once will be enough or do i have to specify for each image???
@arpymastro Once should be enough. Just keep in mind other things you might need to put in between, so keep the overlay and overlay z-indexes high; Maybe 99 and 100 respectively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.