所以我的网站在滚动时遇到了延迟.我只是想问一下,初始化你需要的jQuery对象是否是一个好习惯$(window).scroll(function () {}?
例如:
$(window).scroll(function () {
$thisContainer = $('.section #container');
// 10 more initializations...
$thisContainer.css(); // something like that...
}
Run Code Online (Sandbox Code Playgroud)
我觉得这不是一个好主意,因为每次用户滚动时都会经常调用此函数.当它被调用时,这些变量将被重新初始化.结果会浪费大量的记忆和时间.
谢谢!
有些网站使用以下JavaScript行来构建网站:
document.write('<link rel="stylesheet" type="text/css" href="' + staticpath +
'resources/css/mobile-android.css" /><div class="overlay"></div>
<div class="new-folder-popup" id="message"><div class="new-folder-popup-bg"><div
class="new-folder-header">MEGA for Android</div><div class="new-folder-main-bg">
<div class="new-folder-descr">Do you want to install the latest<br/> version of the MEGA app for Android?</div><a class="new-folder-input left-b/>');
Run Code Online (Sandbox Code Playgroud)
HTML标记是通过vanilla JavaScript生成的,不使用任何库.这段代码是由程序员生成还是编写的?什么样的方法使用这种生成HTML的方式?
我也不知道顺便确定这些是否可行.