html css拖拽设计,css绘制三角形 和 HTML拖拽事件

本文介绍如何使用CSS边框属性绘制三角形,同时详细解释了HTML5中的拖拽事件及其应用场景,包括ondragstart、ondragend等原对象事件与ondragenter、ondrop等目标元素事件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

利用css制作三角形

利用设置边框的三个边的长度和border实现三角形设置,并隐藏其他边

例子:#yz3{

display: inline-block;

0;

height: 0;

border-top: 5px solid transparent;

border-left: 6px solid #F3D995;

border-bottom: 5px solid transparent;

}

HTML拖拽事件(两大种,七小种)

一、原对象事件(被拖拽事件)

ondragstart 拖拽开始

ondrag 拖拽过程

ondragend 拖拽结束

二、目标元素事件(进入的元素)

ondragenter 进入目标元素

ondragover 目标元素上移动

ondragleave 离开目标元素

ondrop 在目标元素上释放

(阻止浏览器默认事件)

例子:

#drag{

150px;

heigh:150px;

background:blue;

}

#box{

500px;

heigh:150px;

border:3px red soild

magin:100px auto

}

//变为可拖动

var oDrag=document.getElementById('drag');

var oBox=document.getElementById('drag');

//原对象事件

//拖拽开始变色

oDrag.οndragstart=function(){

this.style.background='green';

}

//拖拽变色

oDrag.οndrag=function(){

this.innerHTML=‘被拖拽中....’

}

//松开鼠标时改回原色

oDrag.οndragend=function(){

this.style.background='blue';

}

//目标元素事件

//进入时改变颜色

oBox.οndragenter=function(e){

e.preventDefault()//阻止浏览器的默认事件

this.style.background='yellow'

}

//移动时改变颜色

oBox.οndragοver=function(){

e.preventDefault()//阻止浏览器的默认事件

this.style.background='red'

}

//鼠标离开时变色

oBox.οndragleave=function(){

this.style.background='none'

}

//鼠标释放时变色

oBox.οndrοp=function(){

this.style.background='blue'

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值