javascript 向下拖动元素。第一次拖动后跳转
我编写了这段代码,当您单击该元素时,它上面的元素将调整大小更大或更小
当我单击它时,它似乎很好地向下拖动一次,然后尝试再次向下拖动会导致它从屏幕上下来。
function pulldown(element){
var puller = document.getElementById(element);
puller.addEventListener("mousedown", function(e){
var boxStyle = document.getElementById("resizeBox").getAttribute("style");
var currentSize = (boxStyle.match(/\d+/));
var ypos = e.clientY;
var resize = document.getElementById("resizeBox");
resize.style.height = currentSize;
function watchPull(e){
number2 = currentSize + (e.clientY - ypos);
resize.style.height = number2+"px";
}
document.addEventListener("mousemove", watchPull,false);
document.addEventListener("mouseup", function(e){
document.removeEventListener("mousemove", watchPull, false);
number = currentSize + (e.clientY - ypos);
resize.style.height = number+"px";
},false)
},false);
}
pulldown("pullDown");
这就是正在发生的事情。
http://jsfiddle.net/jamcoupe/4hKg8/ (点击“无项目”,然后向下或向上拖动黑线)
I wrote this code that when you click on the element the element above it will resize to be bigger or smaller
When I click on it it seems to drag down nicely once and then trying to drag down again causes it to go down off the screen.
function pulldown(element){
var puller = document.getElementById(element);
puller.addEventListener("mousedown", function(e){
var boxStyle = document.getElementById("resizeBox").getAttribute("style");
var currentSize = (boxStyle.match(/\d+/));
var ypos = e.clientY;
var resize = document.getElementById("resizeBox");
resize.style.height = currentSize;
function watchPull(e){
number2 = currentSize + (e.clientY - ypos);
resize.style.height = number2+"px";
}
document.addEventListener("mousemove", watchPull,false);
document.addEventListener("mouseup", function(e){
document.removeEventListener("mousemove", watchPull, false);
number = currentSize + (e.clientY - ypos);
resize.style.height = number+"px";
},false)
},false);
}
pulldown("pullDown");
here is what is happening.
http://jsfiddle.net/jamcoupe/4hKg8/
(click on "no items" and then drag the black line down or up)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了!
把我的头发拔出来后就是这样!
http://jsfiddle.net/jamcoupe/4hKg8/1/
Solved it!
After pulling my hairs out here is it!
http://jsfiddle.net/jamcoupe/4hKg8/1/