angular - Angular - How to change dropzone color when drag a image
问题描述
I am working with angular and developed an image input. In this input I developed a dropzone that serves to drag the files.
How can I change the dropzone background when dragging a file there? This lets me know if the drop is active to get my file there or not.
Can anyone help me?
HTML
<div class="drop" >
<div class="cont">
<div class="browse" >
Upload
</div>
</div>
<div class="abc">
</div>
<input type="file" id="files" multiple accept="image/*">
</div>
解决方案
使用 Angular 中的拖放事件:
<div (dragenter)="dropzoneHovered = true" (dragleave)="dropzoneHovered = false">
然后在你喜欢的元素上应用 CSS 类:
[class.drag-active]="dropzoneHovered"
例如:
.drag-active {
background: red;
}
你可以在这个 stackblitz中看到它的实际效果
推荐阅读
- tensorflow - 如何使用 pip 安装 tensorflow 版本 1.12.0
- python - 在python中创建一个正则表达式匹配所有hls url
- amazon-web-services - 适用于媒体(视频)流媒体的 AWS 服务
- java - JSON 到多行 Java 字符串转换器
- awk - 了解 OFS 在 AWK 中的工作原理
- php - How to pass variables in url using codeigniter?
- php - 运行多个 sqls 一个需要先运行,然后两个一起运行 PHP
- android - 如何在 for 循环中启动 10 个协程并等待它们全部完成?
- c# - 在 C# 中创建返回值的函数
- oop - 所有权责任和可重用性