Jump to content

Fly in Menus


shadowayex

Recommended Posts

Ok, a few days ago, I saw a cool menu that looked like just a little bar on the side of the window that said "menu". But when you put the mouse over it, the options came in sight. How would I make something like this? I want to add it to a site I'm building, and I also want to add a second one below it for when admins sign in (I'm sure if I learn how to place the menus specifically, I can figure the rest out with PHP. I know enough PHP to create user-based websites.)

Link to comment
Share on other sites

I've figured out how to use that. It's working great. But I want to make it so a second one comes up when admins are logged in. Is there any way to do that? (Note: With my site set up, admins are recognized by a field in my SQL database.)

Link to comment
Share on other sites

Sure you could. Make a Boolean PHP variable to reflect the SQL field value, then inject it into the JavaScript like so:

//JavaScript Documentif(<?= $bool ? 'true' : 'false' ?>){	//show the admin menu}

(But make sure the file is set to have the PHP parsed out of it, either by using a PHP extension - I use '.js.php' with a 'text/javascript' content-type - or by configuring the server to parse PHP in '.js' files. On Apache, the latter would be done in either httpd.conf - or apache.conf depending on the version - or a directory-specific .htaccess file.)

Link to comment
Share on other sites

@_@ It's like a foreign language :). I think I understand, kind of. The deal is, I'm using a free hosting site, so yeah. Not too sure if they have it set to have PHP in .js files and whatnot.

Link to comment
Share on other sites

The deal is, I'm using a free hosting site, so yeah. Not too sure if they have it set to have PHP in .js files and whatnot.
Usually they allow for .htaccess files anyway (while blocking certain directives for security). But just name your JS file .php, no harm.
Link to comment
Share on other sites

@_@ It's like a foreign language :). I think I understand, kind of. The deal is, I'm using a free hosting site, so yeah. Not too sure if they have it set to have PHP in .js files and whatnot.
Heh, yeah, it's kinda hard to get used to echoing source code for a second (semi-)programming language to read. Plus I used compact syntax that isn't as human-readable, so pay attention to where the <?= ?> (which echoes an expression) starts and ends.You probably don't want to parse PHP in all '.js' files unless you frequently use this trick.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...