小编jal*_*mer的帖子

元素未显示在预期位置(x)

我认为我对两个不同的元素(#tu,#chr_1)做了同样的事情,但是由于某些我无法理解的原因,它们表现不同.

我希望反馈元素与拖动窗口和目标位于同一位置,以便我可以就地提供一些反馈.

有趣的是,#chr_1在drop:function中正确对齐,但#tu元素无法做同样的事情.它垂直对齐就好了,但是相对于预期位置有一个很大的偏移量.

此外,#tu元素显示在#chr_x元素下,即使它的z-index更高.

我在这里错过了什么?

https://jsfiddle.net/2s4c7o3c/

                .draggable {font-size: 2em; text-align: center; vertical-align: middle; width: 30px; height: 30px; padding: 0em; float: left; margin: 0em; background-color: orange; z-index: 10; visibility: visible;}

                .droppable {font-size: 2em; text-align: center; vertical-align: middle; width: 30px; height: 30px; padding: 0em; float: left; margin: 0em; background-color: orange; z-index: 10; visibility: visible;}

                <div id="tu" class="draggable" style="visibility:hidden; z-index: 100;"> </div>
                <script>
                    var feedback = $("#tu");
                    feedback.draggable();

                document.write("<div id='chr_"+i+"' class='draggable' style='position:fixed;top:"+y+"px; left:"+x+"px;'>"+phrase.charAt(i)+"</div>");
                var src = $( "#chr_"+i );
                src.draggable();

            //...
                            drop: function( …
Run Code Online (Sandbox Code Playgroud)

javascript css jquery html5 draggable

5
推荐指数
1
解决办法
78
查看次数

如何将代码和单元测试传递给npm测试?

我想在服务器上即时进行单元测试,而无需编写临时文件。有没有办法将要测试的代码和单元测试都传递给npm test?npm测试文档几乎没有内容(https://docs.npmjs.com/cli/test)。另外,也不一定npm test有其他解决方案。

谢谢詹斯

javascript unit-testing node.js npm

1
推荐指数
1
解决办法
224
查看次数

为什么使用数组过滤器的 Promise.all 会产生空数组?

我编写了一个函数来从数组中过滤时间间隔。该功能似乎可以工作,并且打印跳过和接受是适当的并且没有打印错误。但是,它会产生一个空数组。 getDate()是一个返回日期的函数,因此可以使用 将其解析为时间getTime()。这样可行。

async function getInterval(climatedata,harvestdate,period) { 
    return new Promise(function(resolve, reject) {    
        getDate(harvestdate,-1*period).then((sval)=>{
            let start = sval.getTime();
            getDate(harvestdate,0).then(async(eval)=>{
                let end = eval.getTime();
                let filtered = await Promise.all(climatedata.filter((curVal,index,arr) => {
                    getDate(curVal[0]).then((tval)=>{
                        let td = tval.getTime();
                        //console.log(start,td,end);
                        if(td >= start && td <= end) {   
                            console.log("accept"); //although this is printed for the expected subset, nothing is in the filtered array.
                            return true;
                        } else {
                            //console.log("skip");
                            return false;
                        }                    
                    }).catch((err)=>{console.log(err);});
                }));    
                console.log("filtered",filtered); //here I would expect an array with …
Run Code Online (Sandbox Code Playgroud)

javascript arrays filter promise

0
推荐指数
1
解决办法
1185
查看次数

标签 统计

javascript ×3

arrays ×1

css ×1

draggable ×1

filter ×1

html5 ×1

jquery ×1

node.js ×1

npm ×1

promise ×1

unit-testing ×1