Show enlarged picture when mouse hover over an image

后端 未结 3 1711
情话喂你
情话喂你 2020-12-24 10:58

On my webpage, I want to put an image such that when the mouse pointer hovers over that image, an enlarged version will appear.

相关标签:
3条回答
  • 2020-12-24 11:41
    <img src="..." onmouseover="this.width='someWidth'; this.height='someHeight'" onmouseout="this.width='originalWidth'; this.height='originalHeight'">
    
    0 讨论(0)
  • 2020-12-24 11:56

    Updated CSS solution based on further explanation of the requirement in the comments

    http://jsfiddle.net/5sRTX/7/

    <div class="effectback">
    <img class="effectfront" src="https://farm8.staticflickr.com/7042/6873010155_d4160a32a2.jpg" />
    </div>
    
    attribution<br/>
    https://secure.flickr.com/photos/34022876@N06/6873010155/sizes/m/in/photostream/
    
    .effectback {
      display: block;
      background: url('https://farm8.staticflickr.com/7042/6873010155_d4160a32a2_s.jpg') no-repeat;
        margin: 0 auto;
    }
    .effectfront {
      opacity: 0;
      border: none;
      margin: 0 auto;
    }
    .effectfront:hover {
      opacity: 1;
      transition: all 0.3s;
      -webkit-transition: all 0.3s;
    }
    

    Original css solution based on the original question

    CSS solution

    http://jsfiddle.net/ERh62/1/

    .effectscale {
      border: none;
      margin: 0 auto;
    }
    .effectscale:hover {
      -webkit-transform: scale(1.2);
      -moz-transform: scale(1.2);
      -o-transform: scale(1.2);
      transform: scale(1.2);
      transition: all 0.3s;
      -webkit-transition: all 0.3s;
    }
    
    0 讨论(0)
  • 2020-12-24 12:04

    Just try this :

    <html>
    <head>
    <style>
        .container{
            overflow:hidden;
            width:300px;/*change this to whatever you want*/
            height:150px;/*change this to whatever you want*/
    
            /*Of course, to get the desired effect, the size of the image "<img>" below must be larger than the size mentioned above*/
        }
    
        .container:hover{
            overflow:visible
        }
    </style>
    
    </head>
    <body>
        <div class='container'><img src='myImage.png'/></div>
    </body>
    
    </html>
    
    0 讨论(0)
提交回复
热议问题