Last active
February 15, 2016 20:16
-
-
Save mlbd/962311591fb6a5e6db23 to your computer and use it in GitHub Desktop.
This file contains 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
function isMapScrolledIntoView(elem) | |
{ | |
var $elem = $(elem); | |
var $window = $(window); | |
var docViewTop = $window.scrollTop(); | |
var docViewBottom = docViewTop + $window.height(); | |
var elemTop = $elem.offset().top; | |
var elemBottom = elemTop + $elem.height(); | |
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop)); | |
} | |
function initialize() { | |
var styles = [{"featureType":"all","elementType":"all","stylers":[{"saturation":-100},{"gamma":0.5}]}]; | |
var options = { | |
mapTypeControlOptions: { | |
mapTypeIds: ['Styled'] | |
}, | |
center: new google.maps.LatLng(51.524498, -0.078920), | |
zoom: 12, | |
scrollwheel: false, | |
disableDefaultUI: true, | |
navigationControl: false, | |
mapTypeControl: false, | |
scaleControl: false, | |
draggable: true, | |
mapTypeId: 'Styled' | |
}; | |
var contentString = '<div id="content">' + | |
'<h3 id="heading">wplap</h3>' + | |
'<h3>The WordPress Code Express</h3>' + | |
'</div>'; | |
var div = document.getElementById('et-google-map-area'); | |
var map = new google.maps.Map(div, options); | |
var styledMapType = new google.maps.StyledMapType(styles, { | |
name: 'Styled' | |
}); | |
map.mapTypes.set('Styled', styledMapType); | |
var marker = new google.maps.Marker({ | |
position: new google.maps.LatLng(51.524498, -0.078920), | |
map: map, | |
icon: null, | |
}); | |
var infowindow = new google.maps.InfoWindow({ | |
content: contentString, | |
maxWidth: 280 | |
}); | |
var fired = 0; | |
$(window).scroll(function() { | |
if(fired == 0){ | |
if (isMapScrolledIntoView('#et-google-map-view')) { | |
marker.setAnimation(google.maps.Animation.DROP); | |
marker.setIcon("http://i.imgur.com/zORV1Ud.png"); | |
fired = 1; | |
console.log('one time only') | |
} | |
} | |
}); | |
google.maps.event.addListener(marker, 'click', function () { | |
infowindow.open(map, marker); | |
}); | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment