gpt4 book ai didi

javascript - dojo.dnd.moveable,位置为 :fixed

转载 作者:行者123 更新时间:2023-11-30 06:38:51 26 4
gpt4 key购买 nike

我尝试在浏览器窗口中使用固定位置的可移动道场。不幸的是,每次我用鼠标移动 div 时,位置都设置为绝对。我该怎么做才能使 div 固定?

html:

<html>
<body>

<div id="moveMe" style="position:fixed;width:100px;height:100px;border:1px solid black;background-color:#00ff00;cursor:pointer;">bla</div>
<p>test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>
test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>
test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>
test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>
test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>
</body>
</html>

脚本:

dojo.require("dojo.dnd.move");
dojo.ready(function(){

var pcm = new dojo.dnd.move.boxConstrainedMoveable(dojo.byId("moveMe"), {
box : dojo.window.getBox(),
within : true
});

});

测试链接: http://jsfiddle.net/zPVdX/

干杯,克拉特

最佳答案

position: fixedposition: absolute 是浏览器用来确定元素定位方式的两种完全相反的方法。

我首先建议阅读它们之间的差异:http://css-tricks.com/absolute-relative-fixed-positioining-how-do-they-differ/

希望现在您能理解为什么 Dojo draggable 需要将您的元素设置为绝对位置。这允许 Dojo 通过它的 top:left: 属性直观地移动可拖动元素。

将此与静态定位进行比较,静态定位将尝试将您的元素锚定到相对于当前视口(viewport)的位置。

如果您添加更多关于您在视觉上尝试完成的内容的详细信息,可能会有另一种解决方案。

关于javascript - dojo.dnd.moveable,位置为 :fixed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12905958/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com