Is it correct to use JS to make the effects of an HTML?

12

What I want to know is whether it's right to use JavaScript / JQuery to do some button and screen effects, center content horizontally and do certain tasks that can be done by CSS.

The design here of the company said that it is better to use JS / JQuery for performance and maintenance convenience, but I was researching on the subject and it seems that if I use JS it may have several compatibility errors and that is more difficult to fix punctual errors in certain resolutions, devices, and software versions.

To develop web / mobile in a way that supports different screen sizes and different browsers is it correct to use JavaScript to make the animations and layout corrections, or is it correct to use CSS / HTML only? Why?

    
asked by anonymous 23.04.2015 / 19:39

2 answers

5
What can happen is that you want to use CSS features that do not exist in all browsers available on the market today, and in this case, you're going to have problems when you go to a browser that does not have some CSS feature that you used.

When working with Javascript (with or without jQuery, but it is much easier to do with it), this problem is mitigated, since javascript is able to dynamically change the DOM, and thus to detect screen resolution in runtime and choose the best CSS settings.

But it's neither 8 nor 80. Doing everything in Javascript is not a good idea, and doing everything in CSS should not be either. You need to have some sense to know what goes in CSS and what goes in Javascript.

In the case of static properties of classes and ids, it is best to place them in CSS. In Javascript, the most you do is add or remove classes of DOM tree elements.

For properties that vary widely, such as position, size, color, and object shape animations, doing so in CSS would result in a horrible monstrosity of working, if at all possible. In Javascript, you would probably put a few lines of code to fix it.

Anyway, you have to know which one is easier, lighter, and more natural to change. Do not put everything on one side and not everything on the other, put each thing on the side where it looks best, analyzing case by case.

    
23.04.2015 / 21:26
2

The question is somewhat opinion-based but come on. In my answer, I will make a bridge with other doubts your presented here in stackoverflow.

When you work with css to add style, you end up creating a practicality for changes because you or any other programmer can have simplified access via "inspect element", for example.

In everything I create, I try to consider using css and jquery as follows:

  • CSS: I create the initial scene, assign colors, sizes and positions.
  • JSS: I work with events, that is, I create small functions that generate some visual effect or complete the navigation, for example a nav that stays fixed after reaching a scroll X

We can bridge the frameworks and exemplify a little better. Typically staff work with bootstrap on websites and even more vertically-looking web systems. In it you have css components and also js that work similarly to the one described above.

We also have some frameworks with a greater base in the javascript , as is the case of DHTMLX, which generates an interface more oriented to online systems and has a more centralized aspect, without so much vertical work, thinking about the usability of the user. In this case, we have few style sheets and in general, most of the work done via scripts because you can simply drag the div or even resize, for example.

There is no way to say that one method is totally right and another is totally wrong, so your question is about to be closed.

One point that I find interesting to hit is: If you work with a general structure based on css building, try to fix any styling problems by css and < in> vice versa

    
23.04.2015 / 21:26