烧烤-深层链接. FadeIn/FadeOut加载的内容 [英] BBQ - Deeplinking. FadeIn/ FadeOut loaded content
问题描述
我一直在寻找建立一个一页的网站.我正在使用Ben Alman的BBQ.该脚本看起来很扎实,具有良好的注释,并且可以在我所构建的浏览器中使用.现在,我对代码进行了一些修改-在代码被激发之前添加一个暂停,并为加载的内容添加淡入和淡出.
我一直在修改脚本,并为可见的内容添加了暂停和淡出功能-良好的开始....但是当内容淡出时,新内容会直接加载到顶部.最好是我希望淡出可见的内容,然后在完全淡入新内容时淡出.谁能帮我抚平这个婴儿?非常感谢.
I have been looking to build a one page website. I am using BBQ by Ben Alman. The script looks solid, has good commenting and works across the browsers I am building around. Now I am making some adaptations to the code - add a pause before code is fired and to add a fade in and fade out to the loaded content.
I have been tinkering with the script and have added a pause and a fade out to the visible content - good start....but while the content fades out the new content loads straight in over the top. Preferably I would like to fade out visible content then when complete fade in new content. Could anyone help me smooth this baby out? Many Thanks.
$(function(){
setTimeout(run, 4000);
});
function run(){
// Keep a mapping of url-to-container for caching purposes.
var cache = {
// If url is '' (no fragment), display this div's content.
'': $('.bbq-default')
};
// Bind an event to window.onhashchange that, when the history state changes,
// gets the url from the hash and displays either our cached content or fetches
// new content to be displayed.
$(window).bind( 'hashchange', function(e) {
// Get the hash (fragment) as a string, with any leading # removed. Note that
// in jQuery 1.4, you should use e.fragment instead of $.param.fragment().
var url = $.param.fragment();
// Remove .bbq-current class from any previously "current" link(s).
$( 'a.bbq-current' ).removeClass( 'bbq-current' );
// Hide any visible ajax content.
//$( '#content' ).children( ':visible' ).hide();
$( '#content' ).children( ':visible' ).fadeOut('slow');
// Add .bbq-current class to "current" nav link(s), only if url isn't empty.
url && $( 'a[href="#' + url + '"]' ).addClass( 'bbq-current' );
if ( cache[ url ] ) {
// Since the element is already in the cache, it doesn't need to be
// created, so instead of creating it again, let's just show it!
cache[ url ].show();
} else {
// Show "loading" content while AJAX content loads.
$( '.bbq-loading' ).show();
// Create container for this url's content and store a reference to it in
// the cache.
cache[ url ] = $( '<div class="bbq-item"/>' )
// Append the content container to the parent container.
.appendTo( '#content' )
// Load external content via AJAX. Note that in order to keep this
// example streamlined, only the content in .infobox is shown. You'll
// want to change this based on your needs.
.load( url, function(){
// Content loaded, hide "loading" content.
$( '.bbq-loading' ).hide();
});
}
})
// Since the event is only triggered when the hash changes, we need to trigger
// the event now, to handle the hash the page may have loaded with.
$(window).trigger( 'hashchange' );
}
推荐答案
(function(){ setTimeout(run, 4000 ); }); 函数run(){ // 保留url到容器的映射以进行缓存. var 缓存= { // 如果url为(无片段),则显示此div的内容. ' ':
(function(){ setTimeout(run, 4000); }); function run(){ // Keep a mapping of url-to-container for caching purposes. var cache = { // If url is '' (no fragment), display this div's content. '':
(.bbq-default') }; // 将事件绑定到window.onhash,以更改其状态,当历史记录状态更改时, // 从哈希中获取网址,并显示我们缓存的内容或获取的内容 // 要显示的新内容.
('.bbq-default') }; // Bind an event to window.onhashchange that, when the history state changes, // gets the url from the hash and displays either our cached content or fetches // new content to be displayed.
(窗口) .bind(' hashchange',function(e){ // 以字符串形式获取哈希(片段),并删除所有前导#.请注意 // 在jQuery 1.4中,您应该使用e.fragment代替
(window).bind( 'hashchange', function(e) { // Get the hash (fragment) as a string, with any leading # removed. Note that // in jQuery 1.4, you should use e.fragment instead of
这篇关于烧烤-深层链接. FadeIn/FadeOut加载的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!