This article illustrates how jquery implements the option of switching font sizes. Share to everyone for your reference. The implementation methods are as follows:
Copy Code code as follows:
$.fn.switchsize = function (settings) {
Defaults settings
Settings = $.extend ({
Container: ' Body ',
Arrsizeclass: [' small ', ' medium ', ' large '],
Defaultclass: ' Medium ',
Savecookie:true
}, settings);
var $container = $ (Settings.container);
return this
. each (function () {
if ($.cookie (' switchsize ')) {
$container. addclass ($.cookie (' switchsize '));
$ (this). Data ("Current", $.cookie (' switchsize '))
}
})
. bind ("click", Function () {
var pos;
if ($ (this). Data (' current ')} {
pos = Jquery.inarray ($ (this). Data ("current"), Settings.arrsizeclass);
} else {
pos = Jquery.inarray (Settings.defaultclass, Settings.arrsizeclass);
}
if (pos >= 0) {//found Class
if (pos = = settings.arrsizeclass.length-1) {//check if last
$ (this). Data ("current", settings.arrsizeclass[0]);
} else {
$ (this). Data ("current", Settings.arrsizeclass[pos + 1]);
}
} else {
To prevent error
$ (this). Data ("current", settings.arrsizeclass[0]);
}
$container. Removeclass (Settings.arrsizeclass[pos]). AddClass ($ (this). Data ("current");
if (Settings.savecookie = = True) {
$.cookie (' Switchsize ', $ (this). Data ("current"), {expires:365, path: '/'});
}
});
};
I hope this article will help you with your jquery programming.