1.4作业

滚轮事件

window.onmousewheel = function (e) {
if (e.deltaY < 0) {
console.log(“上滑”)
}
else {
console.log(“下滑”)
}
}

bom 浏览器对象模型
  window  history location
  内置对象  String Array  Math  Date
  settimeout  setinterval
 
 obj={}
关闭当前页面或者刷新之前执行的事件  (双核浏览器不显示自定义信息)
    window.onbeforeunload = function () {
        console.log(1);
      return "确认关闭!";
        手机触屏
var startx, starty, endx, endy;
window.addEventListener("touchstart", function (e) {
    var touch = e.touches[0];
    startx = touch.pageX;
    starty = touch.pageY;
})
window.addEventListener("touchmove", function (e) {
    var touch = e.touches[0];
    endx = touch.pageX;
    endy = touch.pageY;
})
window.addEventListener("touchend", function (e) {

// if (startx - endx < 0) {
// console.log(“右”);
// }
// else if (startx - endx > 0) {
// console.log(“左”);
// }
//区分四个方向
var clientx = endx - startx; //正负代表左右
var clienty = endy - starty;
if (Math.abs(clientx) > Math.abs(clienty) && clientx > 0) {
console.log(“right”);
}
else if (Math.abs(clientx) > Math.abs(clienty) && clientx < 0) {
console.log(“left”);
}
else if (Math.abs(clientx) < Math.abs(clienty) && clienty > 0) {
console.log(“down”);
}
else if (Math.abs(clientx) < Math.abs(clienty) && clienty < 0) {
console.log(“up”);
}
)}

拖拽事件

var info = document.querySelector("#info");
// var startx, starty, endx, endy;
document.ondragstart = function (e) {
console.log(“开始拖动:” + e.target.id);
e.dataTransfer.setData(“key”, e.target.id);
// startx= e.pageX;
// starty= e.pageY;
}
document.ondrag = function (e) {
//console.log(“正在拖动:”+ e.pageX+"/"+ e.pageY);
// endx= e.pageX;
// endy= e.pageY;
// var cx=endx-startx;
// var cy=endy-starty;
// var left= parseFloat(e.target.style.left);
// var top= parseFloat(e.target.style.top);
// startx=left+cx;
// starty=top+cy;
// e.target.style.left=startx+“px”;
// e.target.style.top=starty+“px”;
}
document.ondragend = function (e) {
console.log(“拖动完成:” + e.target);
}
document.ondragenter = function (e) {
e.target.style.border=“1px dashed red”;
}
document.ondragover = function (e) {
e.preventDefault();
}
document.οndragleave=function (e){
e.target.style.border="";
}
document.addEventListener(“drop”, function (e) {
var id = e.dataTransfer.getData(“key”);
e.target.appendChild(document.querySelector("#" + id));
e.target.style.border="";

猜你喜欢

转载自blog.csdn.net/weixin_45955339/article/details/103903396
1.4