jQuery setInterval every 300 milliseconds, too much load on browser?

I have been having trouble getting this plugin to attach correctly to ajax loaded elements, and I haven't been able to figure out the reason they sometimes get attached, and sometimes don't. but only for this particular plugin. So my question is, would having a setInterval run something like every 300 milliseconds, or so cause the browser to become sluggish over time if it's just attaching a jquery plugin to certain elements that may or not be on the page. like: setInterval(function(){ $(".nano").nanoScroller(); }, 300); what I have initially tried doing is: $.ajax({ type: "POST", url: "ajax/load/notifications/notifications.php", cache: false, success: function(html){ $(".notification-container").html(html); $(".nano").nanoScroller(); } }); however it's not attaching it (all the way anyways, some parts are being changed, but not the main plugin) However, when I call another ajax event, and trigger the same thing in that callout, it attaches it to this element, and the other element. The setInterval function adds it to them all as well.
In a general sense a 300ms interval isn't a problem; obviously it's what you try to run each interval that might be a problem. And using interval on all ".nano" elements will re-apply .nanoScroller() even to previously processed elements, so that's not terribly efficient. I'd suggest looking more at why your Ajax success code doesn't do it.

以上就是jQuery setInterval every 300 milliseconds, too much load on browser?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准