在javascript中居中图像

时间:2016-08-08 02:30:27

标签: javascript jquery dropzone.js

我是JavaScript的新手。正如您在下面看到的那样,gif文件在重定向之前显示但问题是loading.gif显示在upload-box div之外。如何将它带入div并使其居中(自动边距)。

我尝试了很多方法,但我无法使其发挥作用!

这是JS函数:

//Disabling autoDiscover
Dropzone.autoDiscover = false;
$(function() {

//Dropzone class
var myDropzone = new Dropzone(".dropzone");
myDropzone.on("queuecomplete", function() {

    // Display "Please Wait" gif
    var myImage = new Image();
    var ImgSrc = "./loading.gif";
    myImage.setAttribute("src", ImgSrc);
    myImage.style.margin = "0 auto";
    document.body.appendChild(myImage);

    // Wait 3 seconds and then redirect to the link
    window.setTimeout(function() {
    location.href = 'http://www.i-0s.ir/site';
    }, 3000);
});
});

以下是HTML部分:

<div class="upload-box">
    <p>Please upload your files</p>
    <div class="image_upload_div">
        <form action="upload.php" class="dropzone"></form>
    </div>
</dive>

1 个答案:

答案 0 :(得分:1)

试试这个:

$(function() {
    //Dropzone class
    var myDropzone = new Dropzone(".dropzone");
    myDropzone.on("queuecomplete", function() {

        // Display "Please Wait" gif
        $('.upload-box').append('<div style="text-align:center;"><img src="./loading.gif"/></div>')

        // Wait 3 seconds and then redirect to the link
        window.setTimeout(function() {
            location.href = 'http://www.i-0s.ir/site';
        }, 3000);
    });
});