我正在使用UIZE JavaScript框架在div中移动图像元素。这正常运行。
我想让此功能做另外两件事。
如果用户将图像拖出边界或根本不允许用户将其拖出边界,则自动重置图像的位置。
如果用户将图像拖到示例页面上的预定义位置“绿色框”:www.marklaurel.com/sample.php我想显示一个div,询问用户是否要访问相应图像的网站。
我具有当前由按钮触发的功能:
<script type="text/javascript">
function snapBack()
{
with (document)
{
getElementById('logoUize').style.left = '133';
getElementById('logoUize').style.top = '6';
getElementById('logoPsd').style.left = '240';
getElementById('logoPsd').style.top = '60';
getElementById('logoAfx').style.left = '240';
getElementById('logoAfx').style.top = '206';
getElementById('logoMaya').style.left = '130';
getElementById('logoMaya').style.top = '237';
getElementById('logoHtml5').style.left = '22';
getElementById('logoHtml5').style.top = '194';
getElementById('logoCss3').style.left = '22';
getElementById('logoCss3').style.top = '48';
}
}
</script>
但是,我从浏览器控制台收到此警告:
Warning: Error in parsing value for 'left'. Declaration dropped.
Source File: http://marklaurel.com/sample.php
Line: 0
Warning: Error in parsing value for 'top'. Declaration dropped.
Source File: http://marklaurel.com/sample.php
Line: 0
请让我帮忙使其生效吗?
133
不是有效的CSS位置。您需要133px
或其他单位,例如133em
。
((不用担心,几年前我犯了这个错误,然后想知道为什么我的网站只能在IE:P中工作)
此错误消息是由于element.style.left = 'XX';
与浏览器所期望的不完全相同。您必须说什么是XX。为此,您将使用element.style.left = 'XXpx'
或element.style.left = 'XXem'
或其他任何单位。
有关可用单位的更多详细信息,请参见the spec