JavaScript拖拽文件作为背景图

烁灵 posted @ 2015年6月02日 23:50 in 前端 with tags javascript , 2023 阅读
<!DOCTYPE HTML>
<html>
<head>

</head>
<body>
DROP!!!!!!!!!!
<script type="text/javascript">
function chgImg(evt) {	
    var reader = evt.target;  
	console.log(reader.result);
    var file = reader.file;      
    document.getElementsByTagName("body")[0].setAttribute("style","background-image:url(" + reader.result + ");"); 
}
document.ondragstart = function(e) {
    e.preventDefault();
}
document.ondragover = function(e) {
	e.dataTransfer.dragEffect = 'copy';
    e.preventDefault();
}
document.ondrop = function(e){
	var files = e.dataTransfer.files;
	for(var i = 0, len = files.length; i < len; i++)
	{
		var f = files[i];
		if (f.type.indexOf("image") == -1) {continue;}
        var reader = new FileReader();
        reader.onloadend = chgImg;
        reader.file = f;
        reader.readAsDataURL(f);
	}
    e.preventDefault();
}

</script>
</body>
</html>
Avatar_small
TN SSLC Previous Pap 说:
2022年8月25日 21:44

Tamil Nadu Chennai Board TN SSLC Model Paper 2023, Blueprint Kalvisolai Government Of Tamil Nadu Formed A New Board by Merging the Board Of Secondary Education And Board Of Higher Secondary Examinations 2023,-2023,TN SSLC Previous Paper 2023 TN SSLC Model Paper 2023, Directorate of Government Examination is Conduct the SSLC Examination Month of March to April 2023, TN SSLC Model Paper 2023, Tamil Nadu 10th Sample Questions Paper 2023,

Avatar_small
Alyssa 说:
2023年1月04日 21:50

Adding the ability to drag and drop files into a web page as a background image is a great way to improve the user experience. By allowing users to drag and drop their own CBD vs THC images into the page, they can personalize their experience and make it their own. This can be a great way to increase engagement and encourage users to return to your site.

Avatar_small
Webmail Bluehost 说:
2023年2月03日 15:22

Blue host Webmail allows users to build a professional and personalised email address. Having a personal or corporate brand necessitates a customised email address, which adds trust. Webmail Bluehost Customers would be more interested if you use your company or personal name in the email instead of @outlook or @gmail. Blue host Webmail has capabilities that allow users to generate personal email without having to construct a website.

Avatar_small
BSNL Data Balance Ch 说:
2023年2月09日 15:55

Many of us can check the balance of visa debit card regularly to know whether it is safe or not, Like that only we have to perform BSNL balance check which is a facility for your BSNL mobile number to know every kind of balance and to check the validity, BSNL Data Balance Check but many of us are searching about how to check BSNL balance on new number same under GSM services. BSNL has a host of services and new 4G data plans available on it in comparison to Airtel and Reliance JIO.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter