我有div#container,它包含两个div div.current-content和div.next-content。
两者都充满了一些内容。
如何在下一个内容和当前内容之间切换类而不丢失数据?
这是我最初的理由,但由于这个原因,我失去了当前内容中的一切。
changeContent = function (direction, toLoad) {
if (direction == 'next') {
container.append('<div class="next-content"></div>');
toScroll = -contentWidth;
} else {
container.prepend('<div class="next-content"></div>').css('margin-left', -contentWidth);
toScroll = 0;
}
container.css('width', contentWidth * 2);
$('.current-content, .next-content').css('width', contentWidth);
$('.next-content').load(toLoad, '', function () {
// PSEUDO 3D
if (direction == 'next') {
$('.next-content .content')
.css('margin-left', contentWidth * 2)
.animate({
'margin-left': (contentWidth / 2) - 485
}, {
duration: speed,
easing: 'easeInOutQuad',
complete: function () {
$('.content').css('margin-left', 'auto');
}
});
$('.current-content .content')
.css('margin-left', (contentWidth / 2) - 485)
.animate({
'margin-left': -contentWidth
}, {
duration: speed,
easing: 'easeInOutQuad'
});
} else {
$('.next-content .content')
.css('margin-left', -contentWidth * 2)
.animate({
'margin-left': (contentWidth / 2) - 485
}, {
duration: speed,
easing: 'easeInOutQuad',
complete: function () {
$('.content').css('margin-left', 'auto');
}
});
$('.current-content .content')
.css('margin-left', (contentWidth / 2) - 485)
.animate({
'margin-left': contentWidth * 2
}, {
duration: speed,
easing: 'easeInOutQuad'
});
}
container.animate({
'margin-left': toScroll
}, {
duration: speed,
easing: 'easeInOutQuad',
complete: function () {
container.css({
'margin-left': 0,
'width': 'auto'
});
$('.current-content').remove();
$('.next-content').addClass('current-content').removeClass('next-content');
$('.current-content').css('width', '100%');
}
});
}发布于 2014-02-22 16:34:28
在changeContent函数的末尾,您正在调用:
$('.current-content').remove();这将删除类.current-content的元素。相反,您应该使用css或javascript/jquery来隐藏它。
使用css:
.prev-contentdisplay: none或visibility:hidden使用jQuery:
$("{selector}").hide()隐藏它如果您想要返回,可以删除.prev-content类并添加.current-content返回,或者使用jQuery选择它,然后使用$("{selector}").show()取消隐藏它。
{selector}表示选择器,该选择器只选择要隐藏/显示的元素
https://stackoverflow.com/questions/21956904
复制相似问题