简体   繁体   English

代码在jsfiddle中有效,但在我的网站上不起作用

[英]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.

相关问题 代码在jsfiddle中有效,但是当我将所有代码放入网站时不起作用 - Code works in jsfiddle but doesn't work when I put all the code into my website 当我尝试暂停并在jsFiddle中播放时,我的代码可以工作,但在我的html页面中不起作用 - When I try pause and play in jsFiddle, my code works but it doesn't work in my html page jQuery代码可在jsFiddle中使用,但不能在我的网站上使用 - jQuery code works in jsFiddle but not on my site 我有这个代码在JSFiddle中工作,但不在我的网站上 - I have this code that works in JSFiddle but not on my site 使用javascript隐藏和显示分隔线-在JSFiddle中有效,在网站上不起作用 - Hiding and showing dividers using javascript - Works in JSFiddle, doesn't work on site 来自jsfiddle的代码不起作用 - Code from jsfiddle doesn't work 为什么这段代码在jsfiddle上不起作用? - why doesn't this code work on jsfiddle? 为什么这段代码在jsfiddle中不起作用 - Why does this code doesn't work in jsfiddle 我的网站不喜欢一行代码,但是可以在JSfiddle上运行 - My website doesn't like one line of my code but it works on JSfiddle 上传代码后,我的代码无法在CodePen或JsFiddle上运行,但在浏览器中可以正常运行。 有人能帮我吗? - My code doesn't work on CodePen or JsFiddle when I upload it but works fine in my browser. Would anyone be able to help me please?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM