Customizing Menus in OpenCart: Adding a fisheye menu

In this recipe, we will add a popular fisheye menu into our store shop. We will create the images and change the codes.

1.  Getting started

We will add a menu like this link: http://www.cssplay.co.uk/menus/fisheye8.html

2. How to do it

We will follow these steps:

  1. Like the previous recipe, we will use a fisheye menu from the cssplay Go to this link: http://www.cssplay.co.uk/menus/fisheye8.html. We will use it in our shop.
  2. We will use the Web developer tool to get the css style and related HTML code block for this fisheye menu.
  1. We get the following css code style for the menu from the View Source option:

<style type=”text/css”>

/* ===============================================================

=

This copyright notice must be untouched at all times.

The original version of this stylesheet and the associated (x)html is available at http://www.cssplay.co.uk/menu/fisheye8.html Copyright (c) 2005-2009 Stu Nicholls. All rights reserved.

This stylesheet and the associated (x)html may be modified in any way to fit your requirements.

==================================================================

= */

#container {background:url(fisheye4/background.jpg); width:750px; height:250px; padding-top:50px;}

#holder {width:700px; height:140px; margin:0 auto;}

ul.outer {padding:0; margin:0; list-style:none; width:140px; height:140px; float:left;}

ul.outer ul {padding:0; margin:0; list-style:none;} ul.outer a {text-decoration:none;}

ul.outer li {display:block; float:left; padding:3px; margin:0;}

ul.outer li.inner img.other {width:100%; display:block; border:0; cursor:pointer;}

ul.outer li.inner img.ie6 {display:none;} ul.outer li:hover {padding:1px;}

ul.outer li.inner:hover img {width:128px; height:128px;}

</style>

<!–[if lte IE 6]>

<style type=”text/css”>

ul.outer table {border-collapse:collapse; padding:0; margin:-1px;}

ul.outer li {padding:0;}

ul.outer li a {float:left; display:block; padding:3px;} ul.outer li.inner img.other {display:none;}

ul.outer li.inner img.ie6 {width:100%; display:block; border:0; cursor:pointer;}

ul.outer li.inner img#login {width:100%; background:none; filter:

progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fisheye4/

login.png’, sizingMethod=’scale’);}

ul.outer li.inner img#camera {width:100%; background:none; filter:

progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fisheye4/

camera.png’, sizingMethod=’scale’);}

ul.outer li.inner img#phone {width:100%; background:none; filter:

progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fisheye4/

phone.png’, sizingMethod=’scale’);}

ul.outer li.inner img#find {width:100%; background:none; filter:

progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fisheye4/

find.png’, sizingMethod=’scale’);}

ul.outer li.inner img#printer {width:100%; background:none;

filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fis heye4/

printer.png’, sizingMethod=’scale’);}

ul.outer a:hover {padding:1px;}

</style>

<![endif]–>

  1. We will put this code in either a new css file or we can put it in the tpl file under catalog\view\theme\shop\template\common. If we use a new css file, then we need to add the style file with the link attribute and also get the HTML code for it. We will place it under the div4 class of header ID of header.tpl file:

<div id=”info”>

<h2>Unusual – Fisheye image menu version 3 using just CSS</h2>

<h3>26th August 2009</h3>

<br /><br /><br />

<div id=”container”>

<div id=”holder”>

<ul class=”outer”><li><!–[if lte IE 6]><a href=”#url”><table><tr>

<td><![endif]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr>

<td><![endi f]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr>

<td><![e ndif]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><td><

![endif]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><t d><![endif]–>

<ul><li class=”inner”>

<a href=”#url1″><img class=”ie6″ id=”login” src=”fisheye4/trans.gif” alt=”” />

<img class=”other” src=”fisheye4/login.png” alt=”” /></a>

</li></ul><!–[if lte IE 6]></td></tr></table></ a><![endif]–>

</li></ul><!–[if lte IE 6]></td></tr></table></ a><![endif]–>

</li></ul><!–[if lte IE 6]></td></tr></table></ a><![endif]–>

</li></ul><!–[if lte IE 6]></td></tr></table></a><![endif]-->

</li></ul><!–[if lte IE 6]></td></tr></table></a><![endif]–>

</li></ul>

<ul class=”outer”><li><!–[if lte IE 6]><a href=”#url”><table><tr> <td><![endif]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><td><![endi f]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><td><![en dif]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><td><![endif]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><t d><![endif]–>

<ul><li class=”inner”>

<a href=”#url2″><img class=”ie6″ id=”camera” src=”fisheye4/trans.gif”

alt=”” /><img class=”other” src=”fisheye4/camera.png” alt=”” /></a>

</li></ul><!–[if lte IE 6]></td></tr></table></

a><![endif]–>

</li></ul><!–[if lte IE 6]></td></tr></table></ a><![endif]–>

</li></ul><!–[if lte IE 6]></td></tr></table></ a><![endif]–>

</li></ul><!–[if lte IE 6]></td></tr></table></a><![endif]-->

</li></ul><!–[if lte IE 6]></td></tr></table></a><![endif]–>

</li></ul>

<ul class=”outer”><li><!–[if lte IE 6]><a href=”#url”><table><tr>

<td><![endif]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><td><![endi f]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><td><![e ndif]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><td><![endif]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><t d><![endif]–>

<ul><li class=”inner”>

<a href=”#url3″><img class=”ie6″ id=”phone” src=”fisheye4/trans.gif”

alt=”” /><img class=”other” src=”fisheye4/phone.png” alt=”” /></a>

</li></ul><!–[if lte IE 6]></td></tr></table></

a><![endif]–>

</li></ul><!–[if lte IE 6]></td></tr></table></ a><![endif]–>

</li></ul><!–[if lte IE 6]></td></tr></table></ a><![endif]–>

</li></ul><!–[if lte IE 6]></td></tr></table></a><![endif]-->

</li></ul><!–[if lte IE 6]></td></tr></table></a><![endif]–>

</li></ul>

<ul class=”outer”><li><!–[if lte IE 6]><a href=”#url”><table><tr>

<td><![endif]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><td><![endi f]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><td><![e ndif]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><td><![endif]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><t d><![endif]–>

<ul><li class=”inner”>

<a href=”#url4″><img class=”ie6″ id=”find” src=”fisheye4/trans.gif”

alt=”” /><img class=”other” src=”fisheye4/find.png” alt=”” /></a>

</li></ul><!–[if lte IE 6]></td></tr></table></

a><![endif]–>

</li></ul><!–[if lte IE 6]></td></tr></table></ a><![endif]–>

</li></ul><!–[if lte IE 6]></td></tr></table></ a><![endif]–>

</li></ul><!–[if lte IE 6]></td></tr></table></a><![endif]-->

</li></ul><!–[if lte IE 6]></td></tr></table></a><![endif]–>

</li></ul>

<ul class=”outer”><li><!–[if lte IE 6]><a href=”#url”><table><tr>

<td><![endif]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><td><![endi f]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><td><![e ndif]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><td><![endif]–>

<ul><li><!–[if lte IE 6]><a href=”#url”><table><tr><t d><![endif]–>

<ul><li class=”inner”>

<a href=”#url5″><img class=”ie6″ id=”printer” src=”fisheye4/trans.gif”

alt=”” /><img class=”other” src=”fisheye4/printer.png” alt=”” /></a>

</li></ul><!–[if lte IE 6]></td></tr></table></a><![endif]–>

</li></ul><!–[if lte IE 6]></td></tr></table></ a><![endif]–>

</li></ul><!–[if lte IE 6]></td></tr></table></ a><![endif]–>

</li></ul><!–[if lte IE 6]></td></tr></table></a><![endif]-->

</li></ul><!–[if lte IE 6]></td></tr></table></a><![endif]–>

</li></ul>

</div>

</div>

<br /><br />

<p class=”info”>Copyright &copy;2009 stu nicholls – cssplay. co.uk</p>

<br />

</div> <!– end of info –>

  1. We need to adjust some settings for this HTML code structure. We will add an id on the image tag for each of our menu items. So, the first ID will be home and the code will be as this:

<img class=”ie6″ id=”home” src=” ” alt=”” />

  1. In this way, we will add the other ids in the image tag. Now, we will place an image on the src attribute of the image. We will use the following image and scale height to 150px and the width

  1. We create a png and gif image for each So, our code becomes like this for the home ID of the image:

<a href=”#url1″><img class=”ie6″ id=”home” src=”catalog/view/ theme/shop/image/home-fisheye.gif” alt=”” /><img class=”other” src=”catalog/view/theme/shop/image/home-fisheye.png” alt=”” /></a>

  1. In a similar way, we will add other images to the remaining image tags and change the image id
  2. We also need to add a condition to check whether a user is logged in or On the basis of that we will use login or logout. We can use the following code:

<?php if (!$logged) { ?>

//…

<?php } else { ?>

//…

<?php } ?>

  1. Then, the slider will become like this:

  1. Now, we need to adjust the HTML and css style of the We remove the following code block:

<div id=”info”>

<h2>Unusual – Fisheye image menu version 3 using just CSS</h2>

<h3>26th August 2009</h3>

<br /><br /><br />

//…

<br /><br />

<p class=”info”>Copyright &copy;2009 stu nicholls – cssplay. co.uk</p>

<br />

</div> <!– end of info –>

  1. Also, we will remove the following styles from the css style:

#container {

background:url(fisheye4/background.jpg);

height:250px;

padding-top:50px;

}

  1. When we refresh the browser, we will see the following changes:

  1. Now, again, the following changes:

<div id=”container”>

//…

</div>

And change the style also: #container {

width: 750px;

}

In the stylesheet.css file, we remove this: #header .div4 {

width:510px;

}

  1. So, we get the following image of our menu:

  1. We also remove the background image for each div:

#header .div4 a {

background:url(“../image/tab_1.png”) no-repeat scroll 0 0 transparent;

}

  1. The final status of the our menu becomes like the following:

3.  How it works …

4.  There’s more …

You can also use the html time flylist menu. Go to the link: http://www.cssplay.co.uk/ menus/html-plus-time-flylist-menu.html

5.  See also

 Displaying horizontal sliding menus

Source: Hasan Tahsin (2011), OpenCart 1.4 Template Design Cookbook, Packt Publishing.

Leave a Reply

Your email address will not be published. Required fields are marked *