
This is the continuation of my responsive design series and in this post I'll tell you how to the normal pages widget into a responsive dropdown menu in Blogger.As you know that pages you create in Blogger are displayed in the pages widget but how to make that widget responsive so let see.
Responsive Design
Change the normal pages widget into a responsive dropdown menu (Current Post)
If you've noticed that pages widget automatically changed into drop down when you select the mobile template in the template setting but in my previous post I had told to disable it.So to take out the drop down menu from the page widget you need to change the code of page widget.To change it follow the steps below.
- Go to Template > Edit HTML
- Click on Jump to widget and select PageList1
- Expand the widget script by click the arrow on the left side of the code.
<b:widget id='PageList1' locked='false' title='Pages' type='PageList'>In above script I've highlighted the code,it is the condition that told to change the normal page list into drop down when it is a mobile device but if we remove the condition and enclose it in a
<b:includable id='main'>
<b:if cond='data:title'><h2><data:title/></h2></b:if>
<div class='widget-content'>
<b:if cond='data:mobile'>
<select expr:id='data:widget.instanceId + "_select"'>
<b:loop values='data:links' var='link'>
<b:if cond='data:link.isCurrentPage'>
<option expr:value='data:link.href' selected='selected'><data:link.title/></option>
<b:else/>
<option expr:value='data:link.href'><data:link.title/></option>
</b:if>
</b:loop>
</select>
<span class='pagelist-arrow'>&#9660;</span>
<b:else/>
<ul>
<b:loop values='data:links' var='link'>
<b:if cond='data:link.isCurrentPage'>
<li class='selected'><a expr:href='data:link.href'><data:link.title/></a></li>
<b:else/>
<li><a expr:href='data:link.href'><data:link.title/></a></li>
</b:if>
</b:loop>
</ul>
</b:if>
<b:include name='quickedit'/>
</div>
</b:includable>
</b:widget>
div
with a id='mobnav'
and normal page list into another div
with id='normalnav'
so it will show the drop down menu.As I've changed it below<b:widget id='PageList1' locked='false' title='Pages' type='PageList'>But the problem is that it will show the both navigation the drop down and the normal so simply add the following line in your CSS
<b:includable id='main'>
<b:if cond='data:title'><h2><data:title/></h2></b:if>
<div class='widget-content'>
<div id='mobnav'>
<select expr:id='data:widget.instanceId + "_select"'>
<b:loop values='data:links' var='link'>
<b:if cond='data:link.isCurrentPage'>
<option expr:value='data:link.href' selected='selected'><data:link.title/></option>
<b:else/>
<option expr:value='data:link.href'><data:link.title/></option>
</b:if>
</b:loop>
</select>
<span class='pagelist-arrow'>&#9660;</span>
</div>
<div id='normalnav'>
<ul>
<b:loop values='data:links' var='link'>
<b:if cond='data:link.isCurrentPage'>
<li class='selected'><a expr:href='data:link.href'><data:link.title/></a></li>
<b:else/>
<li><a expr:href='data:link.href'><data:link.title/></a></li>
</b:if>
</b:loop>
</ul>
</div>
<b:include name='quickedit'/>
</div>
</b:includable>
</b:widget>
#mobnavThe above snippet will hide your drop down navigation and in responsive design CSS,set the normal navigation to
{
display:none;
}
display:none
and set the #mobnav
to display:block;
like I've done below.@media screen and (max-width : 800px)Use of above snippet will hide your normal navigation in mobile devices and show your drop down menu.And
{
#mobnav {display:block;}
#PageList1_select {width:100%;}
#normalnav {display:block;}
}
#PageList1_select
is the element of drop down menu so make sure it is set to width:100%.But it will not work until you add the following Jquery script in template.<script>Finally your responsive drop down navigation in ready.
jQuery(document).ready(function($) {
$("<option/>", {
"selected": "selected",
"value" : "",
"text" : "Menu"
}).appendTo(".PageList .widget-content select");
$(".nav .PageList a").each(function() {
var el = $(this);
$("<option/>", {
"value" : el.attr("href"),
"text" : el.text()
}).appendTo(".PageList select");
});
$(".PageList select").change(function() {
window.location = $(this).find("option:selected").val();
});
});
</script>
I do consider all the ideas you've offered in your post.
ReplyDeleteThey're really convincing and can certainly work. Still, the posts
are too brief for beginners. Could you please extend them a bit from next time?
Thanks for the post.
Also visit my web blog :: gym membership deals
I exactly got what you mean, thanks for posting. And, I am too much happy to find this website on the world of Google. free web hosting
ReplyDelete