using minicolors jquery

一个人想着一个人 提交于 2019-12-12 14:25:03

问题


Ive been trying to impliment minicolors. Everything is fine and i have positioned it the way i want but there are some problems implimenting the jquery for me I get this error on the console Uncaught TypeError: Object [object Object] has no method 'miniColors' I have included all jquery files needed.

<script src="javascripts/jquery.minicolors.js"></script>
<link rel="stylesheet" href="stylesheets/jquery.minicolors.css" />

<input class="mini" type="minicolors" data-swatch-position="left" value="#75bd25"  

data-textfield="false" name="color" />


<script type="text/javascript">
$(document).ready( function() {

$('INPUT[type=minicolors]').miniColors({
change: function(hex, rgb) {     $('body').css("background-color",hex); }   
});

});

</script>

THANKS ALOT FOR YOUR HELP!!

this is the reviced code I drew thanks for your help

$(document).ready( function() {

  $('INPUT[type=minicolors]').on('change', function() {

    var input = $(this),
      hex = input.val();

      $('body').css("background-color",hex);

  });

});

there are no errors this time but it is not working what am i doing wrong?

thanks again for the help!


回答1:


UPDATE:

Based on user feedback, the API for MiniColors 2.0 has reverted to a similar approach to 1.0. Please see the updated documentation on GitHub.


Cory here from ABS (plugin author). Both Jason and icktooday are correct. MiniColors 2.0 was launched into beta just a few days ago and the API has indeed changed. 99.9% of developers will just need to include the MiniColors JavaScript file and create an input control like this:

<input type="minicolors" />

The plugin will automatically enable all controls on the page when it first loads. For those who need to add controls dynamically, simply insert the <input> element and then call the init method:

$.minicolors.init();

No need to specify a selector. The plugin works to make it as easy as possible for you with minimal overhead. For more details, refer to the Utility Functions in the docs.

As for your new error, you need to:

  1. Bind the change event to the original input element
  2. Change background-color to backgroundColor
  3. Use the input element's value (and data-opacity attribute if you've enabled opacity)
$('INPUT[type=minicolors]').on('change', function() {

    // This shows how to obtain the hex color and opacity (when in use)
    var hex = $(this).val(),
        opacity = $(this).attr('data-opacity');

    $('BODY').css('backgroundColor', hex);

});

Note: While the previous version of MiniColors was element-based, I felt it was more appropriate to use a forward-thinking approach for 2.0. 99.9% of users will only need to include the MiniColors JavaScript file and add an input element with the minicolors type. For those who need additional functionality, it's just an extra function call to update things.

Please help test out MiniColors 2.0 and submit any bug reports, feature requests, etc. to its home on GitHub.




回答2:


You're using version 2 of MiniColors but are using code that will only work with MiniColors version 1. Use the old version 1 or read the new documentation and update your code.




回答3:


I've never used minicolors before, but it looks like you are trying to use it as a element based plugin (which is how most plugin authors write their plugins), but minicolors appears to be prototype based.

In other words, you can't use $(selector).miniColors(...);, instead you must use $.minicolors.init() and the other functions they support.



来源:https://stackoverflow.com/questions/14000157/using-minicolors-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!