如何在拖放操作期间删除已放置图像的属性?
var holder = document.getElementById('cms');
holder.ondragstart =function(e)
{
dragID =e.srcElement.id;
dregCl =e.srcElement.getAttribute('class');
if(dragID ==='cms_tools'){ cmsPanel =document.getElementById('cms_tools'); }
}
holder.ondragover = function(e)
{
if(dragID ==='cms_tools')
{
cmsPanel.style.top = (e.clientY-7) +'px';
cmsPanel.style.left = (e.clientX-250) +'px'; }}
holder.ondragend = function(e)
{
delete window.dragID;
if(dregCl ==='imglib'){
e.target.removeAttribute('width');
e.target.removeAttribute('height');
e.target.removeAttribute('class'); } }
holder.ondrop = function (e)
{
}
看起来应该很简单。我在面板中有一些图像,其尺寸按 width= 和 height= 缩小,并且需要在图像被放下时将其删除。您现在看到的代码执行此操作,但将其应用于源图像而不是目标图像。我似乎找不到应该用一个词解决方案来解决被删除的图像而不是源图像的问题。请将答案限制在标准 JavaScript 范围内,不要使用专有库或复杂的建议。请不要仅仅因为该项目的要求不包括上述例外情况而关闭此线程。先感谢您。
var holder = document.getElementById('cms');
holder.ondragstart =function(e)
{
dragID =e.srcElement.id;
dregCl =e.srcElement.getAttribute('class');
if(dragID ==='cms_tools'){ cmsPanel =document.getElementById('cms_tools'); }
}
holder.ondragover = function(e)
{
if(dragID ==='cms_tools')
{
cmsPanel.style.top = (e.clientY-7) +'px';
cmsPanel.style.left = (e.clientX-250) +'px'; }}
holder.ondragend = function(e)
{
delete window.dragID;
if(dregCl ==='imglib'){
e.target.removeAttribute('width');
e.target.removeAttribute('height');
e.target.removeAttribute('class'); } }
holder.ondrop = function (e)
{
}
It seems like it should be simple. I have images in a panel that are sized down with width= and height= and need them removed when the image is dropped. The code you see now does this but applies it to the source image instead of the destination image. I cannot seem to find what should be a one word solution to address the image being dropped rather then the source image. Please keep answers constrained to standard javascript, no proprietary libraries or convoluted suggestions. Please do not close this thread simply because this project has requirements that do not include the aforementioned exceptions. Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它只不过是一个单词,但解决方法是简单地阻止Default并插入一张新图像。不是我想要的,但它按预期工作。希望这篇文章可以帮助其他处于类似困境的人。
It was little more than one word but the fix was to simply preventDefault and insert a new image. Not what I was looking for but it works as desired. Hope this post helps anyone else in a similar bind.