gpt4 book ai didi

javascript - .load后jquery效果消失

转载 作者:太空宇宙 更新时间:2023-11-04 14:50:16 24 4
gpt4 key购买 nike

我正在使用此脚本为我的内容添加一些效果(翻转效果和标签)

 <script type="text/javascript" >
$('document').ready(function () {
$('#flip-container').quickFlip();

$('#flip-navigation li a').each(function () {
$(this).click(function () {
$('#flip-navigation li').each(function () {
$(this).removeClass('selected');
});
$(this).parent().addClass('selected');
var flipid = $(this).attr('id').substr(4);
$('#flip-container').quickFlipper({}, flipid, 1);

return false;
});
});
});

但是在 .load(加载页面)之后,效果消失了,我的选项卡的所有内容都显示了。

这是我用来加载内容的代码:

 $(function () {

if (Modernizr.history) {

var newHash = "",
$mainContent = $("#main-content"),
$pageWrap = $("#page-wrap"),
baseHeight = 0,
$el;

$pageWrap.height($pageWrap.height());
baseHeight = $pageWrap.height() - $mainContent.height();

$("nav").delegate("a", "click", function () {
_link = $(this).attr("href");
history.pushState(null, null, _link);
loadContent(_link);
return false;
});

function loadContent(href) {
$mainContent
.find("#guts")
.fadeOut(200, function () {
$mainContent.hide().load(href + " #guts", function () {



$mainContent.fadeIn(200, function () {
$pageWrap.animate({
height: baseHeight + $mainContent.height() + "px"
});
});
$("nav a").removeClass("current");
console.log(href);
$("nav a[href$=" + href + "]").addClass("current");



});
});
}

$(window).bind('popstate', function () {
_link = location.pathname.replace(/^.*[\\\/]/, ''); //get filename only
loadContent(_link);
});

} // otherwise, history is not supported, so nothing fancy here.


});

有没有办法不否定它们?有些主题使用了 on() 函数,但我真的不知道如何在这里使用它。如果可能的话,我希望它无需事先单击某处即可工作。

Here是网站的链接。只有页面 Acceuil 和 Semaine Prochaine 工作。 quickflip 用于第二个。在 Acceuil 上也应该有一些效果(比如 here),但效果只在第一次加载时起作用。

这是更新后的解决方案:

 function loadContent(href) {
$mainContent
.find("#guts")
.fadeOut(200, function () {
$mainContent.hide().load(href + " #guts", function () {
$.getScript('js/jquery.quickflip.min.js', function () {

$('#flip-container').quickFlip();

$('#flip-navigation li a').each(function () {
$(this).click(function () {
$('#flip-navigation li').each(function () {
$(this).removeClass('selected');
});
$(this).parent().addClass('selected');
var flipid = $(this).attr('id').substr(4);
$('#flip-container').quickFlipper({}, flipid, 1);

return false;
});
});

});

$.getScript('tablecloth/tablecloth.js', function () {
tablecloth();
});

$mainContent.fadeIn(200, function () {
$pageWrap.animate({
height: baseHeight + $mainContent.height() + "px"
});
});
$("nav a").removeClass("current");
console.log(href);
$("nav a[href$=" + href + "]").addClass("current");



});
});
}

最佳答案

我认为您需要在执行 load 的函数中添加代码而不是在 document.ready 中:

$('#result').load('ajax/test.html', function() {

$('#flip-container').quickFlip();

$('#flip-navigation li a').each(function () {
$(this).click(function () {
$('#flip-navigation li').each(function () {
$(this).removeClass('selected');
});
$(this).parent().addClass('selected');
var flipid = $(this).attr('id').substr(4);
$('#flip-container').quickFlipper({}, flipid, 1);

return false;
});
});
});
});

显然,行 $('#result').load('ajax/test.html', function()需要修改以匹配您的电话 load .

http://api.jquery.com/load/

原因是#flip-container当您尝试附加 quickFlip 时不存在.你必须调用$('#flip-container').quickFlip();在调用 load 后已完成并检索到您要使用的 HTML quickFlip上。

关于javascript - .load后jquery效果消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17469151/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com