(function($) { $.fn.fontFlex = function(min, max, mid) { var $this = this; $(window).resize(function() { var size = window.innerWidth / mid; if (size < min) size = min; if (size > max) size = max; $this. css ('font-size', size + 'px'); }).trigger('resize'); }; })( jQuery );
<! DOCTYPE html> <html> <head> <script src="js/j query .min.js"></script> <script src="js/fontFlex.js"></script> <script type="text/javascript"> $(function() {$('.text').fontFlex(20, 60, 40);}); </script> </head> <body> <dvi class="text"> <p>Lotus is one of the ten famous flowers in China. It is an aquatic plant for many years. It can be divided into three systems: lotus root, lotus seed and lotus flower. It "emerges from the mud without stain, and washes clean ripples without demon"</ P> <p>In people's minds, lotus is a symbol of nobility and purity. Then why can lotus flowers and leaves "come out of the mud without staining"? It turns out that their outer layers are covered with wax, and there are many papillary projections There is air between the protrusions, blocking the infiltration of muddy water</ p> </div> </body> </html>