25 de mayo de 2012

Como poner un menu despegable en tu blog



Tiempo atrás les hablaba de un tutorial para crear menús desplegables sólo con CSS. Para algunos funcionó bien, pero para otros no. Por eso, veremos otra alternativa simple de implementar, basada en los menús desplegables de las plantillas de Premium Blogger Templates. Este menú usa el plugin jQuery Superfish, y debiese funcionar bien para todos.

Por mas info click en "Lee esta nota completa"


Agregando un menú desplegable a tu plantilla Blogger, paso a paso

1. Carga la última versión de jQuery
Si no tienes jQuery en tu plantilla, puedes cargarlo directamente desde Google, incluyendo la siguiente línea de código en la Edición de HTML de tu plantilla (todos los cambios se harán allí mismo), justo antes de </body>:
1
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js' type='text/javascript'/>
2. Agrega Superfish
Justo después de la línea anterior, pega el siguiente código para incluir jQuery Superfish en tu plantilla:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<script type='text/javascript'>
//<![CDATA[
 
(function($){
 /* hoverIntent by Brian Cherne */
 $.fn.hoverIntent = function(f,g) {
  // default configuration options
  var cfg = {
   sensitivity: 7,
   interval: 100,
   timeout: 0
  };
  // override configuration options with user supplied object
  cfg = $.extend(cfg, g ? { over: f, out: g } : f );
 
  // instantiate variables
  // cX, cY = current X and Y position of mouse, updated by mousemove event
  // pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
  var cX, cY, pX, pY;
 
  // A private function for getting mouse position
  var track = function(ev) {
   cX = ev.pageX;
   cY = ev.pageY;
  };
 
  // A private function for comparing current and previous mouse position
  var compare = function(ev,ob) {
   ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
   // compare mouse positions to see if they've crossed the threshold
   if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
    $(ob).unbind("mousemove",track);
    // set hoverIntent state to true (so mouseOut can be called)
    ob.hoverIntent_s = 1;
    return cfg.over.apply(ob,[ev]);
   } else {
    // set previous coordinates for next time
    pX = cX; pY = cY;
    // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
    ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
   }
  };
 
  // A private function for delaying the mouseOut function
  var delay = function(ev,ob) {
   ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
   ob.hoverIntent_s = 0;
   return cfg.out.apply(ob,[ev]);
  };
 
  // A private function for handling mouse 'hovering'
  var handleHover = function(e) {
   // next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
   var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
   while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
   if ( p == this ) { return false; }
 
   // copy objects to be passed into t (required for event object to be passed in IE)
   var ev = jQuery.extend({},e);
   var ob = this;
 
   // cancel hoverIntent timer if it exists
   if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }
 
   // else e.type == "onmouseover"
   if (e.type == "mouseover") {
    // set "previous" X and Y position based on initial entry point
    pX = ev.pageX; pY = ev.pageY;
    // update "current" X and Y position based on mousemove
    $(ob).bind("mousemove",track);
    // start polling interval (self-calling timeout) to compare mouse coordinates over time
    if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}
 
   // else e.type == "onmouseout"
   } else {
    // unbind expensive mousemove event
    $(ob).unbind("mousemove",track);
    // if hoverIntent state is true, then call the mouseOut function after the specified delay
    if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
   }
  };
 
  // bind the function to the two event listeners
  return this.mouseover(handleHover).mouseout(handleHover);
 };
 
})(jQuery);
 
//]]>
</script>
<script type='text/javascript'>
//<![CDATA[
 
/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 *  http://www.opensource.org/licenses/mit-license.php
 *  http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */
 
;(function($){
 $.fn.superfish = function(op){
 
  var sf = $.fn.superfish,
   c = sf.c,
   $arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
   over = function(){
    var $$ = $(this), menu = getMenu($$);
    clearTimeout(menu.sfTimer);
    $$.showSuperfishUl().siblings().hideSuperfishUl();
   },
   out = function(){
    var $$ = $(this), menu = getMenu($$), o = sf.op;
    clearTimeout(menu.sfTimer);
    menu.sfTimer=setTimeout(function(){
     o.retainPath=($.inArray($$[0],o.$path)>-1);
     $$.hideSuperfishUl();
     if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
    },o.delay); 
   },
   getMenu = function($menu){
    var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
    sf.op = sf.o[menu.serial];
    return menu;
   },
   addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
 
  return this.each(function() {
   var s = this.serial = sf.o.length;
   var o = $.extend({},sf.defaults,op);
   o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
    $(this).addClass([o.hoverClass,c.bcClass].join(' '))
     .filter('li:has(ul)').removeClass(o.pathClass);
   });
   sf.o[s] = sf.op = o;
 
   $('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
    if (o.autoArrows) addArrow( $('>a:first-child',this) );
   })
   .not('.'+c.bcClass)
    .hideSuperfishUl();
 
   var $a = $('a',this);
   $a.each(function(i){
    var $li = $a.eq(i).parents('li');
    $a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
   });
   o.onInit.call(this);
 
  }).each(function() {
   var menuClasses = [c.menuClass];
   if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
   $(this).addClass(menuClasses.join(' '));
  });
 };
 
 var sf = $.fn.superfish;
 sf.o = [];
 sf.op = {};
 sf.IE7fix = function(){
  var o = sf.op;
  if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
   this.toggleClass(sf.c.shadowClass+'-off');
  };
 sf.c = {
  bcClass     : 'sf-breadcrumb',
  menuClass   : 'sf-js-enabled',
  anchorClass : 'sf-with-ul',
  arrowClass  : 'sf-sub-indicator',
  shadowClass : 'sf-shadow'
 };
 sf.defaults = {
  hoverClass : 'sfHover',
  pathClass : 'overideThisToUse',
  pathLevels : 1,
  delay  : 800,
  animation : {opacity:'show'},
  speed  : 'normal',
  autoArrows : true,
  dropShadows : true,
  disableHI : false,  // true disables hoverIntent detection
  onInit  : function(){}, // callback functions
  onBeforeShow: function(){},
  onShow  : function(){},
  onHide  : function(){}
 };
 $.fn.extend({
  hideSuperfishUl : function(){
   var o = sf.op,
    not = (o.retainPath===true) ? o.$path : '';
   o.retainPath = false;
   var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
     .find('>ul').hide().css('visibility','hidden');
   o.onHide.call($ul);
   return this;
  },
  showSuperfishUl : function(){
   var o = sf.op,
    sh = sf.c.shadowClass+'-off',
    $ul = this.addClass(o.hoverClass)
     .find('>ul:hidden').css('visibility','visible');
   sf.IE7fix.call($ul);
   o.onBeforeShow.call($ul);
   $ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
   return this;
  }
 });
 
})(jQuery);
 
//]]>
</script>
 
 
 
 
<script> 
 
    $(document).ready(function(){ 
        $(&quot;ul.menu-secondary&quot;).superfish({ 
            pathClass:  &#39;current&#39; 
        }); 
    }); 
 
</script>
3. El CSS
Pega, justo antes de ]]></b:skin>, los estilos del menú. Podrás notar que no hay ninguna imagen, así que sólo será cosa de cambiar los colores hexadecimales a tu gusto (y quizás una que otra propiedad) una vez que hayas incluido el menú.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* SUPERFISH MENU */
 
.menus,.menus *{margin:0;padding:0;list-style:none;list-style-type:none;}
.menus ul{position:absolute;top:-999em;100%;}
.menus ul li{width:100%}
.menus li:hover{visibility:inherit}
.menus li{float:left;position:relative}
.menus a{display:block;position:relative}
.menus li:hover ul,.menus li.sfHover ul{left:0;top:100%;z-index:99}
.menus li:hover li ul,.menus li.sfHover li ul{top:-999em}
.menus li li:hover ul,.menus li li.sfHover ul{left:100%;top:0}
.menus li li:hover li ul,.menus li li.sfHover li ul{top:-999em}
.menus li li li:hover ul,.menus li li li.sfHover ul{left:100%;top:0}
.sf-shadow ul{padding:0 8px 9px 0;-moz-border-radius-bottomleft:17px;-moz-border-radius-topright:17px;-webkit-border-top-right-radius:17px;-webkit-border-bottom-left-radius:17px}
.menus .sf-shadow ul.sf-shadow-off{background:transparent}
.menu-secondary-wrap{padding:0;margin:0;position:relative;height:40px;z-index:300;background: #F1F1F1; width: 100%;}
.menu-secondary{height:40px}
.menu-secondary ul{min-width:160px}
.menu-secondary li a{color:#1B1A1A;padding:13px 15px 12px 15px;text-decoration:none;text-transform:uppercase;font:bold 12px Arial,Helvetica,Sans-serif; border-right: 1px solid #FFF;}
.menu-secondary li a:hover,.menu-secondary li a:active,.menu-secondary li a:focus,.menu-secondary li:hover > a,.menu-secondary li.current-cat > a,.menu-secondary li.current_page_item > a,.menu-secondary li.current-menu-item > a{color:#FFF;background: #C3C3C3;outline:0;}
.menu-secondary li li a{color:#fff;background:#969696;padding:10px 15px;text-transform:none;font-weight:normal; border-right: 0;}
.menu-secondary li li a:hover,.menu-secondary li li a:active,.menu-secondary li li a:focus,.menu-secondary li li:hover > a,.menu-secondary li li.current-cat > a,.menu-secondary li li.current_page_item > a,.menu-secondary li li.current-menu-item > a{color:#fff;background:#B4B4B4;outline:0}
.menu-secondary a.sf-with-ul{padding-right:26px;min-width:1px}
.menu-secondary .sf-sub-indicator{position:absolute;display:block;overflow:hidden;right:0;top:0;padding:10px 13px 0 0}
.menu-secondary li li .sf-sub-indicator{padding:6px 13px 0 0}
4. El HTML
Copia el siguiente código bajo la cabecera de tu blog, o antes de ésta. Para copiar bajo la cabecera, debes buscar </header> en las plantillas nuevas y poner el códijo justo debajo. En las plantillas más antiguas, deberás poner el código justo antes de    <div id=’content-wrapper’>.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<div class='menu-secondary-wrap'>
<ul class='menus menu-secondary'>
<li><a href='/'>Home</a></li>
<li><a href='#'>Business</a>
<ul class='children'>
<li><a href='#'>Internet</a></li>
<li><a href='#'>Market</a></li>
<li><a href='#'>Stock</a></li>
</ul>
</li>
<li><a href='#'>Downloads</a>
<ul class='children'>
<li><a href='#'>Dvd</a></li>
<li><a href='#'>Games</a></li>
<li><a href='#'>Software</a>
<ul class='children'>
<li><a href='#'>Office</a>
</li>
</ul>
</li>
</ul>
</li>
<li><a href='#'>Parent Category</a>
<ul class='children'>
<li><a href='#'>Child Category 1</a>
<ul class='children'>
<li><a href='#'>Sub Child Category 1</a></li>
<li><a href='#'>Sub Child Category 2</a></li>
<li><a href='#'>Sub Child Category 3</a></li>
</ul>
</li>
<li><a href='#'>Child Category 2</a></li>
<li><a href='#'>Child Category 3</a></li>
<li><a href='#'>Child Category 4</a></li>
</ul>
</li>
<li><a href='#'>Featured</a></li>
<li><a href='#'>Health</a>
<ul class='children'>
<li><a href='#'>Childcare</a></li>
<li><a href='#'>Doctors</a></li>
</ul>
</li>
<li><a href='#'>music</a></li>
<li><a href='#'>politics</a></li>
</ul>
</div>
Ahora sólo queda modificar los enlaces manualmente, reemplazando los textos ancla y los signos gato (#) por tus links con http://.

Finalmente…

Puedes hacer las modificaciones que quieras en el CSS y el HTML de tu menú. No es muy complicado, y sólo depende de tu creatividad.
Lo bueno de un menú desplegable con jerarquías, es que logra una mayor organización en tu blog. Lo único malo que tiene, es que para que funcione en Blogger todos los cambios los tienes que hacer de forma manual.



Via: CB
Creditos: CB

No hay comentarios.:

Publicar un comentario

¡ATENCIÓN: LEE LO SIGUIENTE ANTES DE COMENTAR!

*Si vas a comentar, puedes usar tu cuenta de Google, OpenID, Nombre/Web, y Anónimo
*No Insultar
*No hagas SPAM, Números telefónicos ni Emails
No dejes enlaces a otros blogs, números telefónicos ni correos electrónicos.

¡Gracias!
Att: Staff Club Bloggeras

Categorías

- AgusSweet' -Karii ♥ -SuzettStronger♥' 'Bloggeras' "Personaliza tu Twitter" adelanto Adele aniversario avisos awards BA Bases Bella Thorne bg Biblioteca Blends Blogger Bloggera Del Mes Britney Spears By *.* Memii By Angie By AriiCa'' By Bale By Cata By Deanase By Fatiima By Nievely By Paaz By ProdigyApple By Sweet Perfect By Vale By Venusita By: Ana Laura-JBMFC By: Ayee♥ By: Emii By: Venusita By:Ali♥ By:Leslye Diaz Cyrus Cami Carteles celulares Chicas Color Complementos Concurso coral Crea renders Cursores Demi Lovato Descargas Diana Gu' diseño Ecodesigners Entrega de Pedidos escritoras Especial Famosos Facebook Famosos Flash fonts Foro Fotos GIF gratis Header header psd Header PSD Ariana Grande header psd Demi Lovato hellow iconos Imágenes Imagenes PNG IsOnee Jessie J Katy Perry Laura layout blogger Magazine Manchas Maquillaje Marceliita ♥ Max Rodriguez Me Presento AriiCa'' Me Presento Deanase Me Presento Fatiima Me Presento Paulaah Mega Regalo Mickey Miika♥ Miley Cyrus Minnie Musica navidad NickTVUP Noticias Nueva Coweb Olivia Holt Pack Pandita Para tu blog Para tu Pc Pequeñas Mentirosas Personalizando tu blog PhotoPack photoscape photoshop PhotoshopHQ Piensa verde Pngs Por Cris*-*-* Portadas Post Premades premios Presentacion Programas proximamente Proyecto Verde PSC PSD Psd GomezLove Recursos Regalazos Regalos Reglas Retos rush-designs.fangalaxy.org saarah´ SaaRaH´ Me presento Regalazos samii Keller Screenshots shara marie Sicóloga Rossana Sidebar skins Sofía Dreamer sorpresas Styles Team telenovelas Textos PNG Texturas Themes Tips Tips. Moda Top Tutoriales TV twitter v-blog Vacaciones Video Tutorial videoblog Videos Vídeos votaciones voten por IsOnee para Bloggera del Mes. wallpapers walls Wordpress

LinkWithin

Related Posts Plugin for WordPress, Blogger...