簡體   English   中英

使用拖放HTML上傳圖片

[英]Image upload with Drag & Drop HTML

嗨,我在拖放時遇到問題,我想在整個父親的div處擴展輸入的大小,我不知道為什么,但是輸入是在拖放div下設置的。 有人可以幫助我嗎? 在此處輸入圖片說明

我做了一個小提琴,但是沒用... https://jsfiddle.net/Porcy/jmbcdLbo/

        .uploader{
      text-align: center;
      padding: 1em 0;
      margin: 1em 0;
      color: #555;
      border: 2px dashed #888;
      border-radius: 7px;
      cursor: default;
    }
    #filePhoto{
        position: absolute;
        opacity:0;
        cursor:pointer;
    }

<div onclick="$('#filePhoto').click()" class="uploader">
                        click here or drag here your images for preview and set userprofile_picture data
                        <input type="file" size="32" name="userprofile_picture"  id="filePhoto" />
                      </div>


      var imageLoader = document.getElementById('filePhoto');
      imageLoader.addEventListener('change', handleImage, false);

  function handleImage(e) {
      var reader = new FileReader();
      reader.onload = function (event) {

          $('#blah').attr('src',event.target.result);
      }
      reader.readAsDataURL(e.target.files[0]);
  }

試試這個CSS

此處演示

.uploader {
  position: relative;
  text-align: center;
  padding: 1em 0;
  margin: 1em 0;
  color: #555;
  border: 2px dashed #888;
  border-radius: 7px;
  cursor: default;
}

#filePhoto {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  left: 0;
  right: 0;
  width: 100%;
  top: 0;
  bottom: 0;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM