2015-02-09 44 views
0

http://jsfiddle.net/G5Y8p/9/的jsfiddle代碼在Chrome

不工作我已經複製從該鏈接代碼的jsfiddle它above.But給出的不是我的瀏覽器工作的任何人都可以幫助我? 我是新來的這些東西。

$(document).ready(function() { 

    var $win = $(window), 
     w = 0, 
     h = 0, 
     rgb = [], 
     getWidth = function() { 
      w = $win.width(); 
      h = $win.height(); 
     }; 

    alert($win.width()); 
    $win.resize(getWidth).mousemove(function (e) { 

     rgb = [ 
     Math.round(e.pageX/w * 255), 
     Math.round(e.pageY/h * 255), 
     150]; 

     $('body').css('background-color', 'rgb(' + rgb.join(',') + ')'); 

    }).resize(); 

}); 
+4

你在頁面中包含jQuery庫嗎?這個例子利用jQuery($) – MatthewG 2015-02-09 15:36:15

+2

你必須定義你的意思是「不工作」。你有沒有在控制檯查看任何錯誤(點擊f12並查找控制檯標籤)?預期的行爲與發生了什麼?由於我們無法看到您的瀏覽器,因此這些細節是必需的 – scrappedcola 2015-02-09 15:36:41

回答

1

我想添加這個答案,因爲評論部分根本無法處理內容即時通訊試圖通過。

JS小提琴通常不會在編輯器中運行代碼時生成引用。

嘗試將以下內容添加到您的HTML/PHP或任何您用於標記的文件類型。

<head> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script> 
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" /> 
</head> 

這聽起來像你還沒有包含對JQuery和JQuery UI的必要引用。

+0

非常感謝。有效。沒想到是那麼簡單:) – 2015-02-10 01:55:47