P
P
Philip Gavrilov2018-01-31 16:35:39
JavaScript
Philip Gavrilov, 2018-01-31 16:35:39

How to avoid script code duplication?

There are two fields: name and date.
When you enter data, the font is scaled using a small inputfit plugin script.

The problem is that for the first field I have a maximum text height of 60px, and for the second 30px. And this parameter is regulated in the code of the plugin itself. I don't know how to take it out.

At the moment, I stupidly copy the code with a different name and use two different plugins for two fields, but this is no good. How to solve it correctly?

Example here: https://jsfiddle.net/962p3ffd/1/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OKyJIucT, 2018-01-31
@Filgavrilov

$('.input-name').inputfit({maxSize: 60});
$('.input-date').inputfit({maxSize: 30});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question