วันพุธที่ 10 ตุลาคม พ.ศ. 2555

Simple Jquery CSS Tabs and V3 Google Maps Resize


I had a recent need at work to create tabbed content using Jquery, and include V3 Google maps. Simple right? not likely.
Thanks to Google, I came across an awesome post from Soh Tanaka, posted back in 2009. This was the perfect solution for Jquery tabs, but after a quick embed of google map code, revealed an issue with the version 3 Google map (in a hidden tab), which was loading off center.
Another search on Google revealed this was a bit of a problem, with a few fixes, but none that really worked for me. It turns out that due to the use of the Jquery class “.hide();” google has no reference point for loading the map into the center, meaning it was loading into the top left.



To give the map a reference point, I had to first define some CSS to both the map tab, and the map container, then re-initialize the map function call. I simply added an ID to my map tab link, and used that to call my function.

// Function added to help reset map and container boundaries
        $("#showMap").click(function() {
        $("#tab2").css({'display':'block'});
        $("#map_canvas").css({'width':'630px', 'height':'400px'});
        initialize();
        });

This defined my width and height of both the tab for the content, and my google map, giving it a reference point for the map.
I did have some issues in Internet Explorer, when tabbing between content, reloading the map, resizing the window manually, tabbing, relaoding etc, but this seems to have been fixed (empty function call in the header left for anyone wishing to play with it).

Code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="_LANGUAGE" xml:lang="_LANGUAGE">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple Jquery CSS Tabs and V3 Google Maps</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
<!--
$(document).ready(function() {
	//Default Action
	$(".tab_content").hide();
	$("ul.tabs li:first").addClass("active").show(); 
	$(".tab_content:first").show(); 
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active");
		$(this).addClass("active"); 
		$(".tab_content").hide(); 
		var activeTab = $(this).find("a").attr("href"); 
		$(activeTab).fadeIn();
		if(activeTab == '#tab2') {      
			$(window).resize(function(){
			//$("#tab2").css({'display':'block'});
			//$("#map_canvas").css({'width':'630px', 'height':'400px'});
			//initialize();
			//alert('Changed!');
			}); 
    		}	
		return false;
	});
});
-->
</script>

<style type="text/css" media="screen">
<!--
/* Standard definitions  */
body{font:normal 76.1% "Trebuchet MS", Arial, Helvetica, sans-serif;color:#151515;background:#eaeaea;margin:20px;}
h1{font-size:2.2em;margin:20px 0;}
a:link,a:active,a:visited{background-color:transparent;color:#7aa200;}
a:hover{background-color:transparent;color:#a22600;}
/* Extras  */
.backtohome{border:1px solid #dbdbdb;background-color:#f5f5f5;color:#8f8f8f;-webkit-border-radius:5px 5px 5px 5px;-moz-border-radius:5px;border-radius:5px 5px 5px 5px;padding:5px;}
.hdot{height:1px;border-top:1px dotted #dbdbdb;}
/* Tabbed interface */
.container {width: 670px; margin: 10px auto;}
ul.tabs {margin: 0;padding: 0;float: left;list-style: none;height: 32px;border-bottom: 1px solid #c0c0c0;border-left: 1px solid #c0c0c0;width: 100%;}
ul.tabs li {float: left;margin: 0;padding: 0;height: 31px;line-height: 31px;border: 1px solid #c0c0c0;border-left: none;margin-bottom: -1px;background: #e0e0e0;overflow: hidden;position: relative;}
ul.tabs li a {text-decoration: none;color: #000;display: block;padding: 0 20px;border: 1px solid #fff;outline: none;}
ul.tabs li a:hover {background: #ccc;}	
html ul.tabs li.active, html ul.tabs li.active a:hover  {background: #fff;border-bottom: 1px solid #fff;}
.tab_container {	border: 1px solid #c0c0c0;border-top: none;clear: both;float: left; width: 100%;background: #fff;
-webkit-border-radius: 0px 0px 5px 5px;-moz-border-radius: 0px 0px 5px 5px;border-radius: 0px 0px 5px 5px;}
.tab_content {padding: 20px;}
.tab_content h2 {padding-bottom: 10px;border-bottom: 1px dotted #ddd;}
.tab_content h3 a{color: #254588;}
/* Google map */
#map_canvas {width: 630px; height: 400px;border:1px solid #dbdbdb;}
-->
</style>
</head>
<body>
<div class="container">
	<h1>Simple Jquery CSS Tabs and V3 Google Maps</h1>

    <ul class="tabs">
    <li><a href="#tab1">About</a></li>
    <li><a href="#tab2" id="showMap">Map</a></li>
    <li><a href="#tab3">Contact</a></li>
    </ul>
<!-- Start tab container -->
<div class="tab_container">

    <div id="tab1" class="tab_content">
            <h2>About</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </div>

    <div id="tab2" class="tab_content">
    <h2>Google Map</h2>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript" language="javascript">
    //<![CDATA[
    $(document).ready(function() {
    
      function initialize() {
        var myLatlng = new google.maps.LatLng(-31.952222,115.858889);
        var myOptions = {
          zoom: 14,
          center: myLatlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        
        var contentString = '<div id="content">'+
            '<h1>Perth, Western Australia</h1>'+
            '<div>'+
            '<p><b>Perth</b> is the capital and largest city of the Australian state of Western Australia and the fourth most populous city in Australia</p>'+
            '<p>Attribution: Perth, Western Australia, <a href="http://en.wikipedia.org/wiki/Perth,_Western_Australia">'+
            'http://en.wikipedia.org/wiki/Perth,_Western_Australia</a></p>'+
            '</div>'+
            '</div>';
    
        var infowindow = new google.maps.InfoWindow({
            content: contentString,
            maxWidth: 300
        });
    
        var marker = new google.maps.Marker({
            position: myLatlng,
            map: map,
            title: 'Perth, Western Australia'
        });
        google.maps.event.addListener(marker, 'click', function() {
          infowindow.open(map,marker);
        });
    
      }
    	// Function added to help reset map and container boundaries
        $("#showMap").click(function() {
        $("#tab2").css({'display':'block'});
        $("#map_canvas").css({'width':'630px', 'height':'400px'});
        initialize();
        //alert('showMap Clicked!');
        });
        
     initialize(); 

    });
    //]]>
    </script>
    <div id="map_canvas" style="width:630px;height:400px;"></div>
    </div>

    <div id="tab3" class="tab_content">
		<h2>Contact</h2>
            	<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
                </p>
    </div>
    
</div>
<!-- End tab container -->

<!-- Back Home Footer -->
<div style="clear: both; display: block; padding: 10px 0; text-align:center;">
<div class="backtohome">
<p><a href="http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery">Simple Tabs w/ CSS &amp; jQuery</a> by Soh Tanaka. | 
<a href="http://flintmaker.com">&laquo; Back to Flintmaker</a>
</p>
</div>
</div>
<!-- end back home Footer -->
</div>
</body>
</html>


Enough reading, have a play with the demo, feedback, fixes and improvements appreciated and will be added to the code.

Demo

ref : http://flintmaker.com/code/simple-jquery-css-tabs-and-v3-google-maps/

วันพฤหัสบดีที่ 9 สิงหาคม พ.ศ. 2555

Dock Menu in Website

Dock Menu in Website (same Mac)

1. Download Source Files
Download the CSS dock menu zip package.


2. Insert Code
In between the HTML <head> tag, add the following code

1
2
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/interface.js"></script>

1
<link href="style.css" rel="stylesheet" type="text/css" />

1
2
3
4
5
<!--[if lt IE 7]>
<style type="text/css">
   .dock img { behavior: url(iepngfix.htc) }
   </style>
<![endif]–>


3. Configuration
Don’t forget to add the following code to anywhere within the <body> tag:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<script type="text/javascript">
   $(document).ready(
   function()
   {
   $('#dock2').Fisheye(
   {
   maxWidth: 60,
   items: 'a',
   itemsText: 'span',
   container: '.dock-container2',
   itemWidth: 40,
   proximity: 80,
   alignment : 'left',
   valign: 'bottom',
   halign : 'center'
   }
   )
   }
   );
</script>

4. Add or Remove Items
To add menu item to the top dock (note: span tag is after the img tag):

1
<a class="dock-item" href="#"><img src="images/home.png" alt="home" /><span>Home</span></a> 

To add menu item to the bottom dock (note: span tag is before the img tag):

1
<a class="dock-item2" href="#"><span>Home</span><img src="images/home.png" alt="home" /></a>

reference : http://ndesign-studio.com/blog/css-dock-menu

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Web Hosting Coupons