【发布时间】:2012-11-30 20:01:22
【问题描述】:
好吧,这是一个非常简单的问题……甚至可能是愚蠢的问题。但是我已经尝试了很长时间才能使其正常工作,但没有任何效果。我有一个用加号/减号切换的菜单......这个菜单只适用于主页,但没有别的。代码如下:
$(document).ready(function(){
$('.gh-gallink').toggle(
function() {
$('.gallery_container').animate({
marginTop: "x",
}, 1000);
$('.jquerycssmenu ul li ul').animate({
marginTop: "x",
}, 100);
$('.jquerycssmenu ul li ul li a').animate({
height: "x",
}, 100);
$('#main').animate({
marginTop: "x",
}, 1000);
$(this).text('+');
}, function() {
$('.gallery_container').animate({
marginTop: "x",
}, 1000);
$('.jquerycssmenu ul li ul').animate({
marginTop: "x",
}, 100);
$('.jquerycssmenu ul li ul li a').animate({
height: "x",
}, 100);
$('#main').animate({
marginTop: "x",
}, 1000);
$(this).text('-');
});
});
菜单工作正常,但同样......仅在主页上。当然,我的实际代码中没有 x。但是无论如何,代码在我网站的 header.php 文件中,而且它只适用于我网站的主页。我尝试将“$(document)”更改为“jQuery(Document)”,并且我也停用了所有插件,但菜单仍然只能在主页上使用。
此外,这里是显示切换按钮的 html:
<div class="gallerylink">
<a href="#" class="gh-gallink">
-
</a>
</div>
任何帮助将不胜感激! :)
编辑:
我照着 Chipmunk 说的做了,一个一个地去掉了我标题中的每个脚本。我发现当我删除这个将页面向上滚动到锚点的脚本(如下所列)时,一切正常。但是,我仍然希望同时运行这两个脚本。这是锚滚动脚本。
// When the Document Object Model is ready
jQuery(document).ready(function(){
// 'catTopPosition' is the amount of pixels #invisiblebox
// is from the top of the document
var catTopPosition = jQuery('#invisiblebox').offset().top;
// When #scroll is clicked
jQuery('#scroll, #scrolls').click(function(){
// Scroll down to 'catTopPosition'
jQuery('html, body').animate({scrollTop:catTopPosition}, 'slow');
// Stop the link from acting like a normal anchor link
return false;
});
});
因此,当您单击#scrolls 或#scroll.. 时,它会向上滚动到锚点“#invisiblebox”。我不知道为什么这不适用于我的切换菜单。如果有人有解决方案让这两个脚本运行,请告诉我。
【问题讨论】:
-
这可能是一个愚蠢的问题,但是您是否在其他页面中包含了 jQuery?
-
你确定你的脚本也在其他页面中吗?
-
@Kyle 打败了我。检查您的脚本标签并确保正在加载 jQuery。检查错误控制台中是否有任何明显的“未知变量;$”,这是它的标志。
-
嗨,Kyle,此菜单代码位于我在 wordpress 中的 header.php 文件中,我的网站标题显示在每个页面上。所以从理论上讲,jquery 包含在每一页上。在我的页眉中使用 jquery 的一些其他代码在其他页面上工作,而不是用于切换菜单的这个。我希望这会有所帮助。编辑:哦,我现在明白你的意思了......是的.. jquery 加载在我网站的标题部分中,每个页面上都加载.. 再次,我的标题中的其他一些 jquery 代码工作.. 只是不是这个切换菜单一些愚蠢的理由。 :(
-
可能是另一个愚蠢的问题,但是您是否在 header.php 或 footer.php 中包含脚本标记?还是您通过 wp_enqueue_script 包含在内?
标签: javascript jquery css wordpress