Jump to content
php.lv forumi

class="current"


skrach

Recommended Posts

Sveiki!

Man radās viena problēma. Nekādigi nesanāk uzlikt class="current".

Vienmēr taisīju un viss sanāca, bet tagad tam menu izmantoju javascipt un nevaru likt visu menu iekš PHP.

Iekš <li> ir id="selected pirmajai lapai, tas ir priekš Javascript.

 

Te ir HTML kods kurš atrodas header.php:

    
<ul id="nav"> 
	<li id="selected"><a href="index.php?page=home" class="<?php (($page == 'home') ? 'current' : '')?>">Sākums</a></li>

       <li><a href="index.php?page=services">Pakalpojumi</a></li>
       <li><a href="/" >Noderīgi padomi</a></li>
       <li><a href="index.php?page=gallery" >Galerija</a></li>
       <li><a href="/" >Cenas</a></li>
       <li><a href="index.php?page=contact" >Kontakti</a></li>
</ul>

 

Kods kurš atrodas iekš index.php:

 

<?php
require_once('header.php');


$page = (isset($_GET['page'])) ? $_GET['page'] : '';

switch($page)
       {
               case 'home':
                       include "home.php"; 
               break;

               case 'services':
                       include "services.php";
               break;

	case 'gallery':
                       include "gallery.php";
               break;

	case 'contact':
                       include "contact.php";
               break;

               default:
                       include "home.php";
               break;
       }


require_once('footer.php'); 	
?>

 

CSS kods:

 

#nav {
 position: relative;
 background: #292929;
 top: 50px;
 left: 80px;
}

#nav li {
 float: left;
 list-style: none;
 border-right: 1px solid #111;
 border-left: 1px solid #111;
}

#nav li a {
 color: #e3e3e3;
 position: relative;
 z-index: 2;
 float: left;
 font-size: 12px;
 font-family: helvetica, arial, sans-serif;
 text-decoration: none;
 padding: 10px 15px;
}

#nav li a.current{ 
color: #7e292e;	

}

 

Te ir tas Javascipts kods:

 

(function($) {

$.fn.spasticNav = function(options) {

	options = $.extend({
		overlap : 10,
		speed : 500,
		reset : 1500,
		color : '#61b10a',
		easing : 'easeOutExpo'
	}, options);

	return this.each(function() {

	 	var nav = $(this),
	 		currentPageItem = $('#selected', nav),
	 		blob,
	 		reset;

	 	$('<li id="blob"></li>').css({
	 		width : currentPageItem.outerWidth(),
	 		height : currentPageItem.outerHeight() + options.overlap,
	 		left : currentPageItem.position().left,
	 		top : currentPageItem.position().top - options.overlap / 2,
	 		backgroundColor : options.color
	 	}).appendTo(this);

	 	blob = $('#blob', nav);

		$('li:not(#blob)', nav).hover(function() {
			// mouse over
			clearTimeout(reset);
			blob.animate(
				{
					left : $(this).position().left,
					width : $(this).width()
				},
				{
					duration : options.speed,
					easing : options.easing,
					queue : false
				}
			);
		}, function() {
			// mouse out	
			reset = setTimeout(function() {
				blob.animate({
					width : currentPageItem.outerWidth(),
					left : currentPageItem.position().left
				}, options.speed)
			}, options.reset);

		});


	}); // end each

};

})(jQuery);

Edited by skrach
Link to comment
Share on other sites

Pamaini risinājumu, izskatās, nedaudz šķībs. Pameklē, šeit pat ir bijuši daudz un dažādi risinājumi priekš aktīviem menu.

Link to comment
Share on other sites

Ieraksti iekš header.php sākumā

var_dump($page);

Iespējams, atšķirās php versija, un $_GET masīvs nemaz neeksistē.

Un pārliecinies ar View Source, ka tiešam nav uzlikta tā klase. Iespējams, ka klase ir, bet problēma ir ar JS.

Edited by Леший
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...