jquery - jquery css的负边距
问题描述
当然这个问题很愚蠢,我认为它很愚蠢,但我不知道为什么不在这个用于 css 的 jquery 函数中向我显示负值,我需要发送 -15% 作为 margin-left 和 don '不工作,如果我把这个值放在函数里面,但是通过函数发送不,我不明白这个:
function win(top,width,marginizq)
{
jQuery("#win_background").show(1000);
jQuery("#win_loader").css("margin-top",""+top);
jQuery("#win_loader").css("width",""+width);
jQuery("#win_loader").css("margin-left",""+marginizq);
}
<script>
win("200","30%","-15%");
</script>
一切正常,但如果我将内部函数设置为默认值,则在负值 -15% 时无法正常工作
为什么不这样做?我知道价值必须发送负数或否,对吗?
这是我的问题,谢谢
解决方案
您的脚本似乎工作得很好,尽管margin-top
在您应该添加单位定义(等)的部分px
有%
一个小错字。另外,添加css时不必在变量前添加引号。
即.css("margin-top",""+top)
可以写成.css("margin-top", top)
。
看到它在这里工作正常(纠正错字):
function win(top,width,marginizq)
{
jQuery("#win_loader").css("margin-top", top);
jQuery("#win_loader").css("width", width);
jQuery("#win_loader").css("margin-left", marginizq);
}
win("200px","30%","-15%");
#win_loader{
background:red;
height:200px;
width:100%;
position:absolute;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="win_loader">
</div>
推荐阅读
- websphere - 在 DATASTAGE 中定义日志级别
- javascript - A-Frame:如何在点击时创建可移动实体?
- string - 递归提取给定字符串中引号之间的字符串
- c++ - 如何故意减慢编译速度?
- browser - 等待文件在生成的浏览器中关闭
- r - RShiny:如何访问服务器中的 ui 输入并使用它来打印特定的列表索引?
- haskell - 在 Spock Web 服务器上打印字节串
- java - 使用 Struts 2 的错误 Hibernate 类型映射
- godot - 如何从实例化场景中的另一个场景初始化节点?
- arrays - Swift:将组号分配给元组数组中的元组成员