Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 有问题';在用户选择重置后打开图像位置_Javascript_Html_Css - Fatal编程技术网

Javascript 有问题';在用户选择重置后打开图像位置

Javascript 有问题';在用户选择重置后打开图像位置,javascript,html,css,Javascript,Html,Css,我有一些图像资源(本例中的文件夹),我可以在其中拖动,然后使用“重置”按钮基本上清理它们。但是,在重置位置并再次尝试拖动后,它会将您带回到先前拖动的位置?奇怪吧???非常感谢您的帮助 再次强调,希望解决以下问题: 让用户拖动文件夹/图像 让用户重置/清理 让用户再次拖动,但从“重置”开始 “严格使用”; //清理时重置文件夹位置 $(“.reset position”)。单击(函数(){ //复位位置 $(“.resize drag”).removeAttr(“style”).css(“

我有一些图像资源(本例中的文件夹),我可以在其中拖动,然后使用“重置”按钮基本上清理它们。但是,在重置位置并再次尝试拖动后,它会将您带回到先前拖动的位置?奇怪吧???非常感谢您的帮助

再次强调,希望解决以下问题:

  • 让用户拖动文件夹/图像

  • 让用户重置/清理

  • 让用户再次拖动,但从“重置”开始

  • “严格使用”;
    //清理时重置文件夹位置
    $(“.reset position”)。单击(函数(){
    //复位位置
    $(“.resize drag”).removeAttr(“style”).css(“transition”,“.5s”);
    setTimeout(函数(){
    $(“.resize drag”).removeAttr(“样式”);
    }, 600);
    });
    交互(“调整拖动大小”)
    .拖拉({
    onmove:window.dragMoveListener,
    })
    .可调整大小({
    PreserveSpectratio:false,
    边:{left:false,right:false,bottom:false,top:false},
    })
    .on(“resizemove”,功能(事件){
    var target=event.target,
    x=parseFloat(target.getAttribute(“data-x”))| | 0,
    y=parseFloat(target.getAttribute(“data-y”))| | 0;
    //更新元素的样式
    target.style.width=event.rect.width+“px”;
    target.style.height=event.rect.height+“px”;
    //从上边缘或左边缘调整大小时平移
    x+=event.deltaRect.left;
    y+=event.deltaRect.top;
    target.style.webkitttransform=target.style.transform=
    翻译(“+x+”px,“+y+”px)”;
    target.setAttribute(“数据-x”,x);
    target.setAttribute(“数据-y”,y);
    target.textContent=event.rect.width+“×”+event.rect.height;
    });
    函数dragMoveListener(事件){
    var target=event.target,
    //在data-x/data-y属性中保持拖动位置
    x=(parseFloat(target.getAttribute(“data-x”))| | 0)+event.dx,
    y=(parseFloat(target.getAttribute(“data-y”))| | 0)+event.dy;
    //翻译元素
    target.style.webkitttransform=target.style.transform=
    翻译(“+x+”px,“+y+”px)”;
    //更新posiion属性
    target.setAttribute(“数据-x”,x);
    target.setAttribute(“数据-y”,y);
    }
    :根目录{
    --字体颜色:#000;
    --字体大小:13px;
    }
    html,
    身体{
    溢出:隐藏;
    背景:白色;
    }
    p{
    字体大小:var(--字体大小);
    文本对齐:居中;
    垫面:5px;
    颜色:var(--字体颜色)!重要;
    }
    .folder-container-1{
    宽度:82px;
    位置:绝对位置;
    右:30px;
    排名前10%;
    光标:指针;
    }
    #文件夹{
    宽度:82px;
    显示器:flex;
    对齐内容:居中对齐;
    证明内容:中心;
    }
    #文件夹:活动{
    不透明度:0.7;
    变换:旋转(4deg);
    背景:rgba(0,0,0,0.5);
    边界半径:4px;
    边框:1px纯灰;
    }
    .调整拖动的大小{
    框大小:边框框;
    触摸动作:无!重要;
    用户选择:无!重要;
    }
    .调整容器大小{
    宽度:100%;
    高度:240px;
    }
    
    文件夹重置位置
    文件夹1

    文件夹2

    文件夹3

    重置
    即使重置后,data-x/data-y属性仍附着在可拖动设备上。试着把它去掉,它应该可以正常工作。 我不太清楚为什么需要setTimeout来删除style属性。我添加了一个额外的语句来删除data-x和data-y。也许你可以用一句话来澄清

    $(".reset-position").click(function () {
     // Reset position
     $(".resize-drag").removeAttr("style").css("transition", ".5s");
     $(".resize-drag").removeAttr('data-x data-y');
     setTimeout(function () {
       $(".resize-drag").removeAttr("style");
     }, 600);
    });
    

    非常感谢你!!!setTimeout实际上是我正在使用的另一个属性。我忘了在堆栈上共享它之前把它拔出来。再次感谢你!