gpt4 book ai didi

jQuery 可能的臃肿代码

转载 作者:太空宇宙 更新时间:2023-11-03 20:22:33 24 4
gpt4 key购买 nike

我正在用 jQuery 组合一个动画导航栏,它看起来像很多 js 来实现我想要完成的事情,有人知道更优雅的解决方案吗?

实时站点:

http://daveywhitney.com/nav/2/

jQuery

$(document).ready(function() {

$("#topnav li").prepend("<span></span>");

$("#topnav li").each(function() {
var linkText = $(this).find("a").html();
$(this).find("span").show().html(linkText);
});

$("#topnav li").hover(function() {
$(this).find("span").stop().animate({
marginTop: "-45"
}, 250);
} , function() {
$(this).find("span").stop().animate({
marginTop: "0"
}, 250);
});

});

最佳答案

只需在 CSS 中使用图像 Sprite 和 background-position 即可。那会切断所有的 jQuery。

关于jQuery 可能的臃肿代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6931988/

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