嗨,我有一个包含地图的 div。当用户将鼠标悬停时,我希望它的宽度从 80% 更改为 50%,在右侧创建空间,以容纳将出现在右侧的图像。
我在网上查看了一些 jquery 事件处理的示例,并尝试将我在那里看到的内容整合到我自己的应用程序中。但是,我认为我没有完全正确,因为鼠标悬停没有响应。有人可以帮我诊断错误,因为我是 web 开发、rails 和 jquery 的新手。
以下是我的 rails 项目中的相关文件:
list.html.erb - 包含所有的 HTML
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?key=Q&sensor=false"></script>
<%= stylesheet_link_tag 'application' %>
<%= javascript_include_tag 'application'%>
<%= stylesheet_link_tag 'listings' %>
<body onload="initialize()">
<div id="control_panel">
<input type="button" onclick="getlistings();" value="Add Markers">
<input type="button" onclick="clearMarkers();" value="Remove Markers">
</div>
<div id="info"></div>
<div id="map_canvas" onmouseover="moveLeft();" ></div>
</body>
map.js.erb - 包含 javascript 和 jquery 函数
function moveLeft()
{
$(function(){ $("#map_canvas").bind("mouseover", shiftLeft) });
$(function(){ $("#map_canvas").bind("mouseleave", shiftLeft) });
}
function shiftLeft(evt)
{
$("#map_canvas").toggleClass("shifted_mapCanvas");
}
css 文件:
#map_canvas
{
width: 90%;
height: 90%;
margin-left: auto;
margin-right: auto;
html
{
height: 100%
}
body
{
height: 100%;
margin: 10;
padding: 10
}
}
.shifted_mapCanvas
{
width: 50%;
height: 90%;
margin-left: auto;
margin-right: auto;
html
{
height: 100%
}
body
{
height: 100%;
margin: 10;
padding: 10
}
}