JavaScript - Hide a Div at startup (load)

前端 未结 6 1758
南方客
南方客 2020-12-29 03:17

I have a div in my php page that uses jQuery to hide it once the page has loaded. But is there a way to hide it from the very start of loadup?

The reason I ask is be

6条回答
  •  情书的邮戳
    2020-12-29 03:54

    I've had the same problem.

    Use CSS to hide is not the best solution, because sometimes you want users without JS can see the div.. The cleanest solution is to hide the div with JQuery. But the div is visible about 0.5 seconde, which is problematic if the div is on the top of the page.

    In these cases, I use an intermediate solution, without JQuery. This one works and is immediate :

    This div will be hidden for JS users, and visible for non JS users.

    Of course, you can still add all the effects you want on the div, JQuery toggle() for example. And you will get the best behaviour possible (imho) :

    • for non JS users, the div is visible directly
    • for JS users, the div is hidden and has toggle effect.

提交回复
热议问题