weixin_33722405 2012-05-14 11:42 采纳率: 0%
浏览 31

jQuery地址-动画内容

I'm trying to get an AJAX website with the jquery.address plugin

if you take a look at http://www.idbranding.nl the deep-linking works fine.

The only problem is i can't achieve a loading screen simular like: http://www.nerisson.fr/ (also uses the jquery.address plugin)

So my question is, does anybody knows how to animate the content (FadeOut/FadeIn) and show/hide a loading screen? I think it ain't hard but the documention of jquery.address is limited when it comes to animation.

Here's my code:

function loadURL(url) {
    console.log("loadURL: " + url);
    $("#content").load(url);
}       

// Event handlers
$.address.init(function(event) {
    console.log("init: " + $('[rel=address:' + event.value + ']').attr('href'));
}).change(function(event) {
    $("#content").load($('[rel=address:' + event.value + ']').attr('href'));
    console.log("change");
})

$('a').click(function(){
    loadURL($(this).attr('href'));
});
  • 写回答

1条回答 默认 最新

  • weixin_33721344 2012-05-14 12:09
    关注

    maybe something like this as the load function:

    $("#content").fadeOut("fast", function() { //block of code to be executed when page is faded out
        $("#loadingPlaceholder").fadeIn("fast"); // fade in placeholder (e.g. loading image)
        $.get(url, function(data){ // get the data and if data has been loaded...
            $("#loadingPlaceholder").fadeOut("fast"); // fade out placeholder
            $("#content").empty().html(data).fadeIn("fast"); // empty the innerHTML (--> prevents "flickering"), insert the loaded data and fade in again
        });
    });
    

    furthermore I wouldn't use the click() function, as you would have to apply it to any new links (that may be loaded) --> use delegate/on (don't know which jQuery version you're using) instead ;)

    For a more detailed example check my version https://github.com/peter-m/blueprint/blob/master/js/pushState.js

    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?