Javascript 将文档大小设置为变量并进行比较

Javascript 将文档大小设置为变量并进行比较,javascript,html,css,Javascript,Html,Css,我尝试了不同的方法来比较,如果光标结束位置大于文档总大小的90%,它将把元素设置为90%的高度 当我在元素上拖动框时,菜单将打开 menu.style.top = cursorY.toString() + 'px'; let screenSize = ($(document).height === 90 + '%') if (cursorY.toString() === screenSize){ menu.style.top = 90 + '%

我尝试了不同的方法来比较,如果光标结束位置大于文档总大小的90%,它将把元素设置为90%的高度

当我在元素上拖动框时,菜单将打开

menu.style.top = cursorY.toString() + 'px';
        let screenSize = ($(document).height === 90 + '%')
        if (cursorY.toString() === screenSize){
          menu.style.top = 90 + '%';
        }
如果我使用
cursorY.toString()!==screenSize
cursorY.toString()>screenSize
而不是==它将元素设置为默认值的90%,而不是更改元素的动态位置

const-button=document.getElementById('boundingBox');
const contextMenu=document.getElementById('cntnr')
document.getElementById('boundingBox')。addEventListener('click',()=>{
if(contextMenu.style.display==“块”){
contextMenu.style.display=“无”
}
否则{
contextMenu.style.display=“块”
}
//按钮模拟大于文档大小90%的边界框
/*边界框是一个可拖动的元素,cursorY获取光标的最后位置,并用事件打开菜单
*/
//我不希望我的应用程序溢出整个文档,我希望菜单显示为90%(在我的应用程序上),或者如果我的粗略位置高于80%,则此案例顶部===80%
/*让屏幕大小=($(文档).height()==90+'%'))
if(cursorY.toString()==屏幕大小){
contextMenu.style.top=90+'%';
}
*/
})
正文{
背景色:黑色;
溢出:隐藏;
}
#边界框{
颜色:黑色;
背景色:白色;
}
#cntnr{
显示:无;
位置:绝对位置;
边框:1px实心#F9F9F9;
宽度:150px;
背景#f9f9f9;
边界半径:4px;
z指数:5000;
最高:80%;
}

单击以打开关联菜单

  • 断裂

  • 取消

  • 什么是
    $(文档)
    ?尝试将字符串作为数字进行比较?文档是整个html文档我的意思是什么是$()…它是jQuery选择文档