gpt4 book ai didi

jQuery:类和命名空间

转载 作者:行者123 更新时间:2023-12-01 06:05:20 26 4
gpt4 key购买 nike

我被告知开始在我的 jQuery 代码中使用类和命名空间,对于我们正在构建的新应用程序,我们将使代码变得非常简单和流畅。例如,在登录页面上使用以下代码在淡入之前加载所有内容:

        // Hide the content and fadein the spinner
jQuery(document).ready(function()
{
$('#hide').hide();
$('body').append('<div id="loading">loading...</div>');
$("#loading").hide();
setTimeout($('#loading').fadeIn(), 200);
});

// When all content has loaded, fadeout the spinner and THEN fadein the content
jQuery(window).load(function ()
{
$("#loading").fadeOut("slow", function ()
{
$("#loading").remove();
clearInterval(loadingAnim);
$("#hide").fadeIn("slow");
});
});

var lastx = 0;

var loadingAnim = setInterval(function () { UpdateSpinner("#loading", 42, 504); }, 42);

function UpdateSpinner(target, step, width)
{
$(target).css("background-position", "0 " + lastx + "px");
lastx = (lastx - step) % width;
}

如何使用名称间距和类使这变得更简单?

我所看到的使用示例:http://static.neow.in/js/pegasus/mainpage.js

谢谢

最佳答案

这听起来不像 jQuery 特定请求,而更像是 使用 JavaScript 请求。听起来好像要求您使代码更加封装和面向对象。

How do I declare a namespace in JavaScript? 的解答和 JavaScript: Class.method vs. Class.prototype.method是一个非常好的起点。

关于jQuery:类和命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7084388/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com