[英]Uncaught TypeError: … no method 'dimTheLights'
So I'm writing a little jQuery plugin but for some reason the plugin method isn't being recognised at all. 所以我在写一个jQuery插件,但是由于某种原因,该插件方法根本无法被识别。 Can anyone spot where I've gone wrong below
任何人都可以在下面发现我出了错的地方
jquery.dimlights.js jquery.dimlights.js
(function($) {
var settings = {
opacity : 0.75,
center : false,
}
var screen_width = $(document).width();
var screen_height = $(document).height();
$.fn.dimTheLights = function(options) {
// merge options into settings
options ? $.extend(settings, options) : false;
// add overlay to DOM
$('body').append('<div id="dtl_overlay"></div>');
// resize overlay
$('#dtl_overlay').width(screen_width);
$('#dtl_overlay').height(screen_height);
};
})(jQuery);
index.html index.html
<html>
<head>
<title>Dim The Lights Demo</title>
<link rel="stylesheet" href="reset.css">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="../jquery.dimlights.css">
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="../jquery.dimlights.js"></script>
<script>
$(document).ready(function() {
$('#content img').click(function() {
$(this).dimTheLights();
});
});
</script>
</head>
<body>
<div id="wrapper">
<header>Dim The Lights</header>
<section id="content">
<img src="http://placekitten.com/278/100" class="dimthelights" />
</section>
<footer>
<p>© 2011 • Jordan Adams</p>
<a href="http://twitter.com/jordancalluma">@JordanCallumA</a>
</footer>
</div>
</body>
</html>
(Then I will put it as an answer ;)) (然后,我将其作为答案;)
Try window
instead of document
. 尝试使用
window
而不是document
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.