html - Image Enlarge on Hover -


code: https://jsfiddle.net/xakhlafd/

hello,

i'm trying have image enlarge on hover , use ease transition. works, seems bug out sometimes. tried fix setting:

-webkit-transition-property: height,width; 

but no avail. also, i'm trying understand how author of code (i got of code css blog) achieves this. understand how on hover image changes width, i'm not sure why author setting negative top , left values. have been trying edit width, height, top, , left desired size on hover, seems become skewed - because don't understand negative top , left values doing. can shine light on this? i've read articles on negative margins, don't understand what's being done here.

here's code:

<img src="https://static.pexels.com/photos/70497/pexels-photo-70497.jpeg" class="thumbnail"/> .thumbnail{   width: 100px;   height: 100px; } .thumbnail:hover {     position:relative;     top:-50px;     left:-35px;     width:500px;     height:auto;     display:block;     z-index:999;     cursor: pointer;     -webkit-transition-property: all;     -webkit-transition-duration: 0.3s;     -webkit-transition-timing-function: ease; } 

the top:-50px; left:-35px; rule in css used keep image's center-point unchanged after enlarged. otherwise, when image enlarged, feel moved right-bottom side.

however, not design -- width/height change requires calculating new layout , redraw ui elements on every animation frame, expensive (you can check so difference between repaint , reflow). that's why feel "it seems bug out sometimes."

a better way using transform. please check jsfiddle fix issue. new css code is:

.thumbnail{   width: 100px;   height: 100px;   display:block;   z-index:999;   cursor: pointer;   -webkit-transition-property: all;   -webkit-transition-duration: 0.3s;   -webkit-transition-timing-function: ease; } .thumbnail:hover {     transform: scale(5); } 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -