位置动画在IE上运行缓慢

Animation on position working slow on IE

本文关键字:运行 缓慢 IE 动画 位置      更新时间:2023-09-26

我正在尝试创建html页面,其中笔将移动为文本区域中的用户类型。创造动画,就像我在写作一样上下移动笔。这个动画在chrome中运行得很好,但在IE中却有些滞后。请建议我如何提高动画的速度,使其写为用户类型。虽然IE8不如chrome或任何其他浏览器好,但代码应该在IE8+中工作,请帮助

  var contentHeight = $("#Typing").textareaHelper('height');
            $("#Typing").height(contentHeight);
            localleft = $("#Typing").textareaHelper('caretPos').left + 280;
            localtop = $("#Typing").textareaHelper('caretPos').top;
            $('#Feather').animate({ left: (($("#Typing").textareaHelper('caretPos').left) + 270) },1,animation2);
            $('#Feather').animate({ top: (($("#Typing").textareaHelper('caretPos').top) - 8) }, 1);
            $('#Feather').animate({ left: (($("#Typing").textareaHelper('caretPos').left) + 280) }, 1);
            $('#Feather').animate({ top: $("#Typing").textareaHelper('caretPos').top }, 1);

我要优化的第一件事是搜索DOM的所有时间。每次你这么做。

$("#Typing")

您正在页面中搜索该元素。最好加载一次,然后再操作它。

var $typing = $("#Typing");
// do your animations with $typing.animate();

这可能不能解决整个问题,但这是一个开始。

编辑:对$("#Feather")做同样的操作