gpt4 book ai didi

javascript - 重叠格式

转载 作者:行者123 更新时间:2023-12-02 18:57:55 25 4
gpt4 key购买 nike

我有一个函数 isOverlap ,它告诉两个对象是否重叠,这是源代码:

    function isOverlap(idOne,idTwo){
var objOne=$("#"+idOne),
objTwo=$("#"+idTwo),
offsetOne = objOne.offset(),
offsetTwo = objTwo.offset(),
topOne=offsetOne.top,
topTwo=offsetTwo.top,
leftOne=offsetOne.left,
leftTwo=offsetTwo.left,
widthOne = objOne.width(),
widthTwo = objTwo.width(),
heightOne = objOne.height(),
heightTwo = objTwo.height();
var leftTop = leftTwo > leftOne && leftTwo < leftOne+widthOne
&& topTwo > topOne && topTwo < topOne+heightOne,
rightTop = leftTwo+widthTwo > leftOne && leftTwo+widthTwo < leftOne+widthOne
&& topTwo > topOne && topTwo < topOne+heightOne,
leftBottom = leftTwo > leftOne && leftTwo < leftOne+widthOne
&& topTwo+heightTwo > topOne && topTwo+heightTwo < topOne+heightOne,
rightBottom = leftTwo+widthTwo > leftOne && leftTwo+widthTwo < leftOne+widthOne
&& topTwo+heightTwo > topOne && topTwo+heightTwo < topOne+heightOne;
return leftTop || rightTop || leftBottom || rightBottom;
}

我主要需要的是如何格式化调用函数,有什么帮助吗?这是我失败的尝试:

   if($(document).isOverlap("#mario", ".block")) {
$(".block").hide("explode", { pieces: 16 }, 100);
});

你可以找到我正在尝试制作的程序 here

最佳答案

isOverlap("#mario", ".block")

您传递给此函数的字符串是完整的 jQuery 选择器。

因此,函数内部的"#"+idOne变成了"##mario",这显然是错误的。

此外,如果这些选择器中的任何一个匹配多个元素,您的代码将无法正常工作。

关于javascript - 重叠格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15142013/

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