简体   繁体   English

复制到Dreamweaver中时,Jsfiddle无法正常工作

[英]Jsfiddle won't work when copying into Dreamweaver

I've been trying to solve this by myself, and I just can't figure out what I'm doing wrong. 我一直在尝试自己解决这个问题,但我无法弄清楚自己在做什么错。 But this jsfiddle: http://jsfiddle.net/3964w/3/ completely stops working when I try to work with it in Dreamweaver. 但是当我尝试在Dreamweaver中使用它时,此jsfiddle: http : //jsfiddle.net/3964w/3/完全停止工作。

Here is my html code, if that helps. 这是我的html代码,如果有帮助的话。 I'm feeling so lost on this, and I think it should be pretty easy. 我对此感到迷茫,我认为这应该很容易。 If someone could explain what I'm doing wrong I would be very grateful. 如果有人可以解释我在做什么错,我将不胜感激。

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>testing jquery</title>
<link href="styles.css" rel="stylesheet" type="text/css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<script>

var mouseX = 0, mouseY = 0, limitX = 150-15, limitY = 150-15;
$(window).mousemove(function(e){
  var offset = $('.container').offset();
   mouseX = Math.min(e.pageX - offset.left, limitX);
   mouseY = Math.min(e.pageY - offset.top, limitY);
   if (mouseX < 0) mouseX = 0;
   if (mouseY < 0) mouseY = 0;
});

// cache the selector
var follower = $("#follower");
var xp = 0, yp = 0;
var loop = setInterval(function(){
    // change 12 to alter damping higher is slower
    xp += (mouseX - xp) / 12;
    yp += (mouseY - yp) / 12;
    follower.css({left:xp, top:yp});

}, 30);

</script>    

</head>

<body>

<div class="centerdiv">
    <div class="container">
        <div id="follower"></div>
    </div>
</div>

</body>

</html>

Are you calling jQuery from a CDN or a local directory? 您是从CDN还是本地目录调用jQuery? If from a CDN it won't work unless the page is being run from a server, like localhost. 如果使用CDN,则除非从服务器(如localhost)运行该页面,否则它将无法正常工作。 So if you don't have a local server set up then download a copy of jQuery and put it inside the directory where you are putting JavaScript files and call it from there. 因此,如果您没有设置本地服务器,请下载jQuery的副本,并将其放在要放置JavaScript文件的目录中,然后从那里调用它。

Or USe this 或使用这个

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

or write your code inside document ready function 或在文档准备功能中编写代码

<script type="text/javascript"> 
$(document).ready(function()
{ /* Your Code Here */ });
 </script>

style.css is missing, and style.css丢失,并且

I will replace 我会取代

ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js

by 通过

<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM