简体   繁体   English

Javascript可以在IE中正常运行,但运行缓慢,为什么?

[英]Javascript works fine but very slowly in IE, why?

Excuse my ignorance for I'm a rookie programmer and my language mistakes for I'm a non native english speaker. 对我是菜鸟程序员的无知和对我不是英语母语的人的语言错误感到抱歉。

I've got a page that, on some click events triggers some javascript and loads ,via php, content into an iframe which also performs some javascript actions (on itself and on the parent page). 我有一个页面,该页面在发生某些单击事件时会触发一些javascript,并通过php将内容加载到iframe中,该iframe也将执行一些javascript操作(在其自身和父页面上)。 Everything works fine on FF and all the features work fine in IE too. 在FF上一切正常,在IE中所有功能也正常。 But the performance in IE is terribly slow...one of the main features is to change opacity of some pictures on mouse up, and it takes 2s+ for IE to display the new opacity. 但是IE中的性能非常慢...主要功能之一是在鼠标向上移动时更改某些图片的不透明度,而IE显示新的不透明度需要2s +。 Why? 为什么? and more important, what can I do to fix it? 更重要的是,我该如何解决?

Thanks in advance, Irene 预先感谢,艾琳

IE has a horribly slow JavaScript engine compared to every other major browser (I'm speaking to IE8 not IE9+)...that's just how it is. 与其他主流浏览器相比,IE具有非常慢的JavaScript引擎(我是在说IE8,而不是IE9 +)……事实就是如此。 You may want to disable certain things in IE, and of course optimize your script overall. 您可能要禁用IE中的某些功能,并且当然要对脚本进行整体优化。

You may for example want to disable the fade in IE, or give it far fewer frames (longer interval in-between steps), because of its DirectX opacity filter, it's much slower than other browsers in most fade situations. 例如,您可能想要禁用IE中的淡入淡出效果,或为其提供更少的帧(在步骤之间更长的间隔),因为其DirectX不透明度过滤器在大多数淡入淡出情况下比其他浏览器要慢得多。

To profile performance problems specific to IE, I highly recommend dynaTrace AJAX edition , it's a free performance profiler made just for IE. 为了分析特定于IE的性能问题,我强烈推荐dynaTrace AJAX版 ,它是专为IE制作的免费性能分析器。

Benchmarks showing how slow things can be in IE: http://www.favbrowser.com/chrome-vs-opera-vs-firefox-vs-internet-explorer-vs-safari/ 基准测试可显示IE中的速度有多慢: http//www.favbrowser.com/chrome-vs-opera-vs-firefox-vs-internet-explorer-vs-safari/

You might need to experiment with different ways of manipulating the DOM to increase the performance in IE. 您可能需要尝试使用各种操作DOM的方法来提高IE的性能。

IE is known to be a bit slow (sarcasm). 已知IE有点慢(讽刺)。 I don't know exactly what you are doing, but maybe you might want to remove some effects if the user is using IE? 我不知道您在做什么,但是如果用户使用IE,也许您可​​能想删除一些效果? Maybe you are doing a lot of DOM changes. 也许您正在做很多DOM更改。

It would be handy to see the code in order to give you tips on how to get a better performance. 看到代码将很方便,以便为您提供有关如何获得更好性能的提示。

Ok, here you go, this is probably the script that's creating most of the problems...any suggestions? 好的,开始吧,这可能是造成大多数问题的脚本……有什么建议吗?

$(function() {

$("#myTable").draggable({
    containment:'parent',
    drag:function() {
        $("#myTable").css("opacity", "0.6");
        $("#myTable").css("background-image", 'none');
        $("#galframe").css("opacity", "1.0");

    },
    stop:function(){
        $("#myTable").css("opacity", "1.0");
        $("#galframe").css("opacity", "0.6");
        var $image = $("#galframe").contents().find("#jgal div.active img");
                var src=$image[0].src;
                $("#myTable").css("background-image", 'url(' + src + ')');
                $position = $("#myTable").position();
                $("#myTable").css("backgroundPosition", (-parseInt($position.left)+549).toString()+ "px " + (-parseInt($position.top)+20).toString() + "px");
                $("#myTable").css("background-repeat", "no-repeat");
            }
});
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM