[英]Code works in jsfiddle but doesn't work on my site
I have coded a div that is mostly hidden until clicked on where it expands and then is hidden again when clicked on. 我已经对div进行了编码,在单击它展开的位置之前,它基本上是隐藏的,然后在单击时再次隐藏。 You can look at the jsfiddle for that here: http://jsfiddle.net/Z8vEs/1/ 您可以在这里查看jsfiddle: http : //jsfiddle.net/Z8vEs/1/
I have used this method on another website and it works there, but for some reason not on a new website I am crafting, and frankly I am stumped and frustrated. 我已经在另一个网站上使用了这种方法,并且可以在该网站上使用,但是由于某种原因,我不在自己制作的新网站上使用它,并且坦率地说,我感到沮丧和沮丧。 I am not very well versed in jQuery so I am not sure how to go about debugging, so any suggestions would be appreciated. 我不太精通jQuery,所以我不确定如何进行调试,因此任何建议将不胜感激。 The only other jQuery I am using is an edited version of an image slider from codrops: http://tympanus.net/codrops/2011/08/09/portfolio-image-navigation/ 我使用的唯一其他jQuery是来自codrops的图像滑块的编辑版本: http ://tympanus.net/codrops/2011/08/09/portfolio-image-navigation/
You can view my website to see the issue for yourself at http://quintinmarcus.com/ 您可以在http://quintinmarcus.com/上查看我的网站以亲自了解此问题。
Thanks for any help -Quintin 感谢您的帮助-Quintin
It doesn't look like you are loading jQuery properly on your website. 您似乎无法在自己的网站上正确加载jQuery。
Inside the javascript file named custom.js you can see this: 在名为custom.js的javascript文件中,您可以看到以下内容:
/* ANIMATE ABOUT BOX */
$("#about").click(function() {
if($('#about').css('width') == '83px'){
$('#about').animate({'width':'380px'},350);
$('#about').animate({'height':'457px'},350);
}
else{
$('#about').animate({'width':'83px'},350);
$('#about').animate({'height':'11px'},350);
}
});
When it should really look like this: 何时真正看起来像这样:
/* ANIMATE ABOUT BOX */
$(document).ready(function(){
$("#about").click(function() {
if($('#about').css('width') == '83px'){
$('#about').animate({'width':'380px'},350);
$('#about').animate({'height':'457px'},350);
}
else{
$('#about').animate({'width':'83px'},350);
$('#about').animate({'height':'11px'},350);
}
});
});
Note the jQuery initiating script and closing tags at the top and bottom of the new version. 注意新版本顶部和底部的jQuery初始化脚本和结束标记。
jsfiddle is adding that code by default for you since it is so common. jsfiddle会为您默认添加该代码,因为它是如此常见。
Because 'custom.js' file is loaded before <div id="about">
is created, you might wanna do something like this: 由于在创建<div id="about">
之前已加载“ custom.js”文件,因此您可能想要执行以下操作:
$(document).ready(function() {
$("#about").click(function() {
if($('#about').css('width') == '83px'){
$('#about').animate({'width':'380px'},350);
$('#about').animate({'height':'457px'},350);
}
else{
$('#about').animate({'width':'83px'},350);
$('#about').animate({'height':'11px'},350);
}
});
});
I think there is an illegal character at the end of your script. 我认为您的脚本结尾处有一个非法字符。 I put this into the console and it worked (I removed the character): 我把它放到控制台中,并且起作用了(我删除了字符):
$("#about").click(function() { if ($('#about').css('width') == '83px') { $('#about').animate({ 'width': '380px' }, 350); $('#about').animate({ 'height': '457px' }, 350); } else { $('#about').animate({ 'width': '83px' }, 350); $('#about').animate({ 'height': '11px' }, 350); } });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.