Expand Div over others on mouse over jquery

后端 未结 3 1668
有刺的猬
有刺的猬 2021-01-01 04:13

i\'m actually trying to build a products list inside a table. I already have the php code which takes data from db and places in the page but i\'m stuck with jquery and java

3条回答
  •  天涯浪人
    2021-01-01 05:04

    Answer has been reworked based on the OP's clarification of his question

    You will have to position .contenitore absolutely and position it from the top left corner of the parent container .principale. The parent should have a relative position while the content child should be absolutely positioned.

    .principale {
        height: 240px;
        width: 210px;
        position: relative;
    }
    .principale .contenitore {
        background-color: #fff;
        height: 240px;
        width: 210px;
        position: absolute;
        display: block;
        top: 0;
        left: 0;
    }
    

    Also, you cannot use text-align: center to center the image element. Instead use margin: 15px auto:

    .immagine {
        border: 1px solid maroon;
        margin: 15px auto;
        height: 168px;
        width: 168px;
        position:relative;
    }
    

    Upon the hover event, you change the size of the content and also animate the top and left positions:

    $(window).load(function(){
    $('.contenitore').hover(function() {
        $(this).animate({
            width: 300,
            height: 400,
            top: -80,  // Half the height difference 0.5*(400-240)
            left: -45  // Half the width difference 0.5*(300-210)
        }, 'fast');
        $(this).animate().css('box-shadow', '0 0 5px #000');
        $(this).css({
            zIndex: 100  // Change z-index so that is the positioned above other neighbouring cells
        });
    }, function() {
        $(this).animate().css('box-shadow', 'none')
        $(this).animate({
            width: 210,
            height: 240,
            top: 0,
            left: 0
        }, 'fast');
        $(this).css({
            zIndex: 1
        });
    });
    });
    

    See fiddle here - http://jsfiddle.net/teddyrised/EWJGJ/6/

提交回复
热议问题