代码之家  ›  专栏  ›  技术社区  ›  FlatAssembler

在较旧的Internet Explorer中,拖放元素被粘在光标上

  •  0
  • FlatAssembler  · 技术社区  · 6 年前

    若要重现此错误,请在Internet Explorer 6中打开以下web应用程序(我相信在某些较新版本的Internet Explorer中也会出现相同的错误,因为在以兼容模式运行时,Internet Explorer 11中也会出现此错误,该模式应模拟Internet Explorer 8):
    http://flatassembler.000webhostapp.com/compiler.html
    现在,在右上角,你应该看到三个按钮。
    点击左边的第一个,最小化按钮。

    你知道发生了什么事吗?有什么快速的解决办法吗?下面是我用来实现拖放功能的代码:

    <!-- ... -->
    <div id="ikona"
                style="text-align:center; display:none; position:absolute; color:white; font-family:Arial; font-size:10px;">
                <img src="https://www.theflatearthsociety.org/forum/avr/avatar_1461509_1483220545.png" alt="AEC" style="width:75px;" draggable="false"/><br/>
                <span id="opis">Arithmetic<br/>Expression<br/>Compiler</span>
            </div>
            <script type="text/javascript">
        //...
    document.getElementById("smanji").onclick=function() { //The "minimize" button.
                        //...
            document.getElementById("ikona").style.display="block";
                        document.getElementById("opis").style.backgroundColor="transparent";
                        document.getElementsByTagName("nav")[0].style.display="none";
                        document.getElementById("ikona").style.left=document.body.clientWidth/2-document.getElementById("ikona").offsetWidth/2;
                        document.getElementById("ikona").style.top="auto";
                        document.getElementById("ikona").style.bottom="8px";
                    }
            //...
            if (!(/(M|m)obile/.test(navigator.userAgent))) {
            //...
            document.getElementById("ikona").onclick=function()
                        {
                            document.getElementById("opis").style.backgroundColor="blue";
                        }
                        document.getElementById("ikona").onmousedown=function()
                        {
                            dragInit(this);
                        }
            //...
        }
        //...
            var isFirefox=false;
            var selected;
            var x_pos = 0;
            var y_pos = 0;
            var x_elem = 0;
            var y_elem = 0;
            function dragInit(elem) {
                selected = elem;
                x_elem = x_pos - selected.offsetLeft;
                y_elem = y_pos - selected.offsetTop;
            }
            function moveElement(e) {
                if (!window.event) {
                    isFirefox=true;
                    window.event=new Object();
                }
                if (isFirefox)
                {
                    window.event.clientX=e.clientX;
                    window.event.clientY=e.clientY;
                }
                x_pos = window.event.clientX;
                y_pos = window.event.clientY;
                if (selected) {
                    selected.style.left = (x_pos - x_elem) + 'px';
                    selected.style.top = (y_pos - y_elem) + 'px';
                }
            }
            function destroy(e) {
                if (!window.event) {
                    isFirefox=true;
                    window.event=new Object();
                }
                if (isFirefox)
                {
                    window.event.clientX=e.clientX;
                    window.event.clientY=e.clientY;
                }
                if (window.event.clientX<document.getElementById("ikona").style.left.substring(0,document.getElementById("ikona").style.left.length-2)*1
                    || window.event.clientX>document.getElementById("ikona").style.left.substring(0,document.getElementById("ikona").style.left.length-2)*1+document.getElementById("ikona").offsetWidth
                    || window.event.clientY<document.getElementById("ikona").style.top.substring(0,document.getElementById("ikona").style.top.length-2)*1
                    || window.event.clientY>document.getElementById("ikona").style.top.substring(0,document.getElementById("ikona").style.top.length-2)*1+document.getElementById("ikona").offsetHeight)
                        document.getElementById("opis").style.backgroundColor="transparent";                selected = null;
            }
            document.onmousemove = moveElement;
            document.onmouseup = destroy;`
    //...
        </script>
    <!-- ... -->
    

    对于一些仍在使用旧版本Internet Explorer的网站访问者。。。

    0 回复  |  直到 6 年前