随意div大小拖动组件_以最简单的方式创建可调整大小和可拖动的角度组件

随意div大小拖动组件

A resizable and draggable HTML div element can add more possibilities into your website by allowing you to make more flexible components, such as a draggable back-to-top button, a resizable calendar, a movable video window and etc.

可调整大小和可拖动HTML div元素可以允许您制作更灵活的组件,例如可拖动的自上而下的按钮,可调整大小的日历,可移动的视频窗口等,从而可以为您的网站增加更多的可能性。

In this post, we will go through the process of making a resizable and draggable component step by step with less than 100 lines of code. The structure of this article is shown below:

在本文中,我们将逐步使用不到100行的代码逐步制作可调整大小和可拖动的组件。 本文的结构如下所示:

  1. Create a resizable component

    创建一个可调整大小的组件
  2. Make the component draggable

    使组件可拖动
  3. Add boundary restrictions into moving & resizing actions

    在移动和调整大小的动作中添加边界限制

View details in my github repo: angular-resizable-draggable.

在我的github repo中查看详细信息: angular-resizable-draggable

1.创建可调整大小的组件 (1. Create a resizable component)

1.1组件初始化 (1.1 Component Initialization)

As part of the initial settings, I have initialized an Angular project with a 600x450px container for the component we are going to make.

作为初始设置的一部分,我已经为要制作的组件初始化了一个600x450px容器的Angular项目。

After that, we need to initialize a resizable-draggable component and pass some initial @Input values into the component, and bind them with the component’s style.

之后,我们需要初始化一个可调整大小的可拖动组件,并将一些初始@Input值传递给组件,然后将其与组件的样式绑定。

Image for post
Initialize Component
初始化组件

app.component.html

app.component.html

<app-resizable-draggable 
[width]="300"
[height]="150"
[left]="100"
[top]="100">
</app-resizable-draggable>

resizable-draggable.component.ts

resizable-draggable.component.ts

@Input('width') public width: number;
@Input('height') public height: number;
@Input('left') public left: number;
@Input
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值