J'ai effectué une recherche sur le SO et je ne peux pas mettre à jour le plugin de ma mine correctement. J'ai mis les options de plugin sur init mais j'ai besoin de changer les valeurs de chaque paramètre après et réexécuter le plugin. Voici ce que j'ai jusqu'à présent:Mise à jour des paramètres du plugin jQuery après l'initialisation
(function ($) {
$.fn.testPlugin = function (options) {
\t \t // Default settings
var settings = $.extend({
padding: '0',
margin: '0'
}, options);
return this.each(function() {
\t $(this).css({
\t 'padding' : settings.padding,
'margin' : settings.margin
});
});
}
}(jQuery));
// Initialize the plugin
$('#main').testPlugin({
padding: '20px',
margin: '20px 0'
});
// Update the plugin settings with new values and change the padding/margin on click
$('#update').on('click', function() {
var newPadding = $('#newPadding').val();
var newMargin = $('#newMargin').val();
console.log(newPadding, newMargin)
// Here is where i'm stuck.
// How to update the plugin settings and re-run it?
})
#main {
width: 300px;
background: #333;
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="main">
<p>Lorem ipsum dummy text</p>
</div>
<input type="text" id="newPadding" value="20px" />
<input type="text" id="newMargin" value="20px 0" />
<button id="update">Update</button>
Je pense pas :) Merci! – g5wx