简体   繁体   English

谁能帮我弄清楚为什么我无法让jQuery震动效果在我的div上起作用?

[英]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.

相关问题 需要帮助弄清楚为什么我无法在我的代码游乐场使用Javascript获取某个textarea元素的内容 - Need help figuring out why I can't get the content of a certain textarea element with Javascript for my code playground 为什么我的 guildMemberAdd 不起作用? 任何人都可以帮助我吗? - why my guildMemberAdd dont work? anyone can help me? 我的代码在$(document).ready()函数中不起作用。 谁能帮我理解原因? - My code doesn't work within a $(document).ready() function. Can anyone help me understand why? 正则表达式不起作用。 我的代码有什么问题? 谁能帮我解决这个问题 - Regex doesn't work. What's wrong with my code? Can anyone help me fix this 谁能帮我使用 JQuery 对我的时间块进行颜色编码? - Can anyone help me colorcode my time blocks using JQuery? 我尝试创建一个图像弹出窗口但在这里我的脚本严重失败任何人都可以帮助我 - I tried creating a image popup but failed badly here my script anyone can help me out 当我将 animation 效果包装在 function 中时,它停止工作。 谁能告诉我为什么? - When I wrap my animation effect in a function, it stops working. Can anyone tell me why? 谁能帮我解释为什么这个循环不起作用? - Can anyone help me on why this loop isn't working? 谁能帮我告诉我为什么我在函数中得到一个空值 - Can anyone help and tell me why do i get a null value in the function 我需要帮助弄清楚为什么这个“if”语句不起作用 - I need help figuring out why this 'if' statement wont work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM