ajax中slidedown,JQuery slidedown menu without ajax

这段代码展示了如何使用jQuery实现点击链接时动态填充菜单,并通过AJAX防止内容缓存。当链接被点击时,菜单会下滑显示,同时更新页面hash。通过修改dd.load为dd.html可以直接插入自定义内容,而无需使用AJAX。此外,还建议使用jQuery UI tabs实现可折叠的内容,以简化代码。
摘要由CSDN通过智能技术生成

I copied part of their js.

// populates the menu according to what link was clicked, opens it if not already opened

populateMenu: function (currentLink) {

dd.removeClass(pages);

dd.addClass(currentLink + " open");

dd.slideDown(speed, function () {

// callback that runs after menu finishes sliding down

$("nav ul li.menu>a.active").find("span").html(upArrow);

// ajax call is below; it appends a timestamp to prevent caching, in case of dynamic content; remove if you like

dd.load(dir + "/" + currentLink + ext + "?" + new Date().getTime(), function () {

// callback that runs after menu finishes loading

dd.removeClass("loading");

addCloseLink();

});

});

// change the hash according to the clicked link

document.location.hash = currentLink;

},

If you change the dd.load call for a modify statement with jQuery like dd.html(...) with the content of your choice, you do not have to use ajax.

If you remove the document.location.hash = currentLink; line at the end of the function, it will not modify your back/forward navigation.

That would end up looking something like:

populateMenu: function (currentLink) {

dd.removeClass(pages);

dd.addClass(currentLink + " open");

dd.slideDown(speed, function () {

// callback that runs after menu finishes sliding down

$("nav ul li.menu>a.active").find("span").html(upArrow);

dd.html($('#your_source_here'));

dd.removeClass("loading");

addCloseLink();

});

},

Edit:

You could also use a jQueryUI tabs with collapsible content, see demo here. It would require styling but should work with maybe less work than adapting the previous code.

See this jsFiddle for a basic example. Only the styling of the tabs need to be done.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值