Created
December 19, 2012 02:06
-
-
Save cwoodley/4333789 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <head> | |
| <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js'></script> | |
| <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js'></script> | |
| <style> | |
| #map_viewport { | |
| cursor: move; | |
| height: 795px; | |
| overflow: hidden; | |
| position: relative; | |
| width: 750px; | |
| z-index: 10; | |
| } | |
| #marker { | |
| background: red; | |
| cursor: pointer; | |
| display: block; | |
| height: 20px; | |
| width: 20px; | |
| z-index: 9999; | |
| } | |
| </style> | |
| <script> | |
| jQuery(document).ready(function($) { | |
| // #map_viewport is our "mask", i.e the visible part of the map image to the user | |
| // #map_content holds our map image and property markers | |
| // get the height/width of the map image | |
| $("#map_content img").load(function() { | |
| var $mapContentWidth = $("#map_content .map_image").width(); | |
| var $mapContentHeight = $("#map_content .map_image").height(); | |
| // set the map_content container to match the map dimensions | |
| $('#map_content').height($mapContentHeight).width($mapContentWidth); | |
| }); | |
| // initialize jQ UI's draggable helper | |
| $("#map_content").draggable({ | |
| drag: function(event, ui) { | |
| if(ui.position.top>0) { ui.position.top = 0; } | |
| // set maxtop | |
| var maxtop = ui.helper.parent().height()-ui.helper.height(); // #map_viewport height - #map_content height | |
| // if maxtop is set, #map_content is draggable until its top margin is equal to maxtop. | |
| if(ui.position.top<maxtop) { ui.position.top = maxtop; } // | |
| if(ui.position.left>0) { ui.position.left = 0; } | |
| // set maxleft | |
| var maxleft = ui.helper.parent().width()-ui.helper.width(); | |
| // if maxleft is set, #map_content is draggable until its left margin is equal to maxleft. | |
| if(ui.position.left<maxleft) { ui.position.left = maxleft; } | |
| } | |
| }); | |
| $("#marker").draggable({ | |
| stop: function() { | |
| $posX = $(this).css('left'); | |
| $posY = $(this).css('top'); | |
| $('span#posX').text($posX); | |
| $('span#posY').text($posY); | |
| } | |
| }); | |
| }); | |
| </script> | |
| </head> | |
| <div id="primary"> | |
| <div id="map_viewport"> | |
| <div id="map_content"> | |
| <div id="marker"></div> | |
| <img src="http://110.143.190.111/qubeappartments/wp-content/themes/qubeapartments/media/images/maps/pertharea.jpg" class="map_image" /> | |
| </div> | |
| </div> | |
| <p id="">X: <span id="posX"></span></p> | |
| <p id="">Y: <span id="posY"></span></p> | |
| </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment