[英]Can anyone help me in figuring out why I can't get Jquery shake effect to work on my div?
I've attached a JSfiddle of what my problem is. 我附上了我的问题所在的JSfiddle。 Everything else on the click of the button works except the shake effect and I cant seem to figure out why?
除了抖动效果外,单击按钮的其他所有内容都起作用,我似乎无法弄清楚为什么? I've tried changing it around etc but it still wont do it?
我已经尝试过将其更改为其他位置,但是它仍然不会这样做?
https://jsfiddle.net/g8t5ts8x/ https://jsfiddle.net/g8t5ts8x/
$(document).ready(function() { for(var i = 0; i < 16; i++) { for(var j = 0; j < 16; j++) { $('#grid').append('<div class= square></div>'); }; }; $(".square").mouseenter(function() { $(this).css("background-color", "#7fffd4"); }); //clears the canvas and resets the color on hover back to #7fffd4// $("#clear").click(function() { $("#grid").effect("shake", {times:4}, 1000); $(".square").css("background-color", "white"); $(".square").mouseenter(function() { $(this).css("background-color", "#7fffd4"); }); }); //creates a random color for each square when button is clicked// $("#randomcolor").click(function() { $(".square").mouseenter(function() { var randomColorChange = '#'+ (Math.random()*0xFFFFFF<<0).toString(16); $(this).css('background-color', randomColorChange); }); }); });
* { margin: 0; padding: 0; border: 0; box-sizing: border-box; } body { font-family: Arial, sans-serif; background-color: white; } h1 { color: white; padding-top: 8px; padding-bottom: 8px; text-align: center; background-color: #191919; } span { text-decoration: underline; color: #7fffd4; } .buttons { padding-top: 10px; text-align: center; width: 480px; margin: 0 auto; } #clear, #randomcolor { margin: 5px; padding: 8px; border-radius: 1px; background-color: #191919; color: white; } .container { margin-top: 20px; } #grid { width: 484px; height: 484px; margin: 10px auto; border: 2px solid black; box-shadow: 2px 2px 30px 10px grey; } .square { width: 30px; height: 30px; margin: 0px; float: left; background: white; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"> </script> <h1>Etch A <span>Sketch</span></h1> <div class="buttons"> <button id="clear">Reset Canvas</button> <button id="randomcolor">Random Colors</button> </div> <div class="container"> <div id="grid"></div> </div>
Thanks! 谢谢!
$('selector').effect()
is a jQueryUI feature. $('selector').effect()
是jQueryUI的功能。 Your fiddle does not reference the jQueryUI libs. 您的小提琴未引用jQueryUI库。
Include references to a CDN source such as: 包括对CDN源的引用,例如:
https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js
https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui .min.js
When I add these to your fiddle I see shaky buttons on click. 当我将这些添加到您的小提琴中时,单击时会看到摇晃的按钮。
I have found to my own cost to check the separation between JQuery base and JQuery UI, and make no assumptions. 我已经自费检查JQuery基本库和JQuery UI之间的分离,并且没有做任何假设。 JQuery swallows your errors if you refer to unknown methods in many cases so if you see something you expect to occur is not happening and it's a UI effect then check your assumptions.
如果您在许多情况下引用未知方法,则JQuery会吞下您的错误,因此,如果看到预期发生的事情没有发生,并且是UI效果,请检查您的假设。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.