Jquery 显示未正确设置动画和未捕获目标中的所有链接
本质上,我试图将内容加载到一个div中,从该div中的一个链接开始。现在它在一定程度上起作用了。到目前为止,我的代码从目标div抓取链接,然后单击设置“content”div的动画,并在目标链接处替换为“content”divJquery 显示未正确设置动画和未捕获目标中的所有链接,jquery,animation,hide,show,target,Jquery,Animation,Hide,Show,Target,本质上,我试图将内容加载到一个div中,从该div中的一个链接开始。现在它在一定程度上起作用了。到目前为止,我的代码从目标div抓取链接,然后单击设置“content”div的动画,并在目标链接处替换为“content”div //Target links and call on click $('#scrollbox li a').click(function(){ //Define load paramaters var toLoad = $(this).attr('href')+' #
//Target links and call on click
$('#scrollbox li a').click(function(){
//Define load paramaters
var toLoad = $(this).attr('href')+' #content';
//Hide content
$('#content').hide('fast',loadContent);
//Remove Load Bar
$('#load').remove();
//Show Load Bar
$('#wrapper').append('<span id="load">LOADING...</span>');
$('#load').fadeIn('normal');
function loadContent() {
$('#content').empty().load(toLoad,'',showNewContent())
}
function showNewContent() {
$('#content').show('slow',hideLoader());
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;
});
//点击目标链接和调用
$('#滚动框LIA')。单击(函数(){
//定义加载参数
var toLoad=$(this.attr('href')+'#content';
//隐藏内容
$('content').hide('fast',loadContent);
//拆下负载杆
$(“#加载”).remove();
//显示加载条
$(“#包装器”).append('LOADING…');
$('加载').fadeIn('正常');
函数loadContent(){
$('#content').empty().load(toLoad',showNewContent())
}
函数showNewContent(){
$('content').show('slow',hideLoader());
}
函数hideLoader(){
$('加载').fadeOut('正常');
}
返回false;
});
第一个问题是,在隐藏旧内容后,在显示新内容时,动画是断断续续的,旧内容仍然可见,并在动画中显示,直到最后一毫秒,新内容才“闪烁”。旧内容不应该隐藏而新内容不应该显示吗?我试图用.empty修复这个问题,但现在它只是弹进来,好像根本没有.show动画
第二个问题是,我的任何代码似乎都会影响的唯一链接是目标div中的标题链接,“content”div(目标div中)中的链接不会受到影响,并重新加载整个页面。我是否需要将目标锁定在部门内的部门?我的代码中没有针对div内的所有链接吗
如果您需要进一步的澄清,请让我知道
干杯并感谢您的帮助。已修复。将动画设置为
0
,以便根本没有动画。(这算是一个便宜的解决办法)
使用.live()
命令在重新加载时将命令绑定到所有后续链接
$(document).ready(function(){
$('.scroll-pane').jScrollPane({showArrows: true});
$('#scrollbox a').live('click', function() {
//all elements that exist now and elements added later
//with this class have this click event attached
//Define load paramaters
var toLoad = $(this).attr('href')+' #content';
//Hide content
$('#content').hide(0,loadContent);
function loadContent() {
$('#content').load(toLoad,'',showNewContent())
}
function showNewContent() {
$('#content').fadeIn(0);
}
return false;
});
});