1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JS Bin</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } .wrapper { width: 150px; height: 150px; margin: 20px; display: flex; justify-content: center; align-items: center; border-radius: 50%; overflow: hidden; position: relative; box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.5); } .wrapper:hover { cursor: pointer; } .wrapper img { max-width: 100%; height: 100%; } #imageInput { position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; z-index: 1; cursor: pointer; } .wrapper .upload { display: none; position: absolute; top: 0; right: 0; width: 100%; height: 100%; justify-content: center; align-items: center; background: rgba(0, 0, 0, 0.5); color: white; } .wrapper:hover .upload { display: flex; }
</style> </head> <body> <div class="wrapper"> <img src="https://i.loli.net/2018/03/01/5a979cd405a66.jpg" > <div class="upload">点我上传</div> <input id="imageInput" type="file"> </div> <script> imageInput.onchange = function(e) { e.target.value = '' } </script> </body> </html>
|