简体   繁体   中英

JSFiddle code not working in Chrome

http://jsfiddle.net/G5Y8p/9/

I have copied this JSFiddle code from the link given above.But it is not working in my browser can anyone help me with this? I am new in these things.

$(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();

});

I want to add this as an answer because the comments section simply cannot handle the content im trying to get across.

JS Fiddle does not normally generate references when you run code in the editor.

Try adding the following to your HTML/PHP or whatever file type you are using for markup.

<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>

It sounds like you havent included the necessary references to both JQuery and JQuery UI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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