尝试使用 jquery 缩放和平移图像地图时出现问题

发布于 2024-09-24 03:09:47 字数 3695 浏览 1 评论 0原文

〜我已经在这方面工作了一段时间(好几个月!!)——使用 jquery 缩放和平移图像地图——这有点超出了我目前的技能水平,所以我很高兴我已经走到这一步了!!~但是功能并没有想象中那么流畅(放大和缩小需要更流畅)——并且在IE7中查看时存在一些更大的问题。

它位于网页上:http://www.agencydr.squarespace.com/locations

下面是使用的jquery。 有人注意到我应该改变什么吗?

/* ************************************** */
/* locations map */
/* ************************************** */
$('#modulePage6955407 #sectionContent3019160').insertAfter("#pageHeaderWrapper");
$('#modulePage6955407 #bannerAreaWrapper').animate({"top": "+=250px"}, "slow");
$('#modulePage6955407 #sectionContent3019160').animate({"height": "290px"}, "slow");
$('#modulePage6955407 #sectionContent3019160').animate({"opacity": "1"}, "slow");

$('#LocationsMapWrapper').hover(function() {
   $('#LocationsMapWrapper #MapImage').animate({
      width: 600,
      height: 375,
      marginLeft: 550,
      marginTop: -20
   }, "slow", "easeOutQuad");
 },
 function() {
   $('#LocationsMapWrapper #MapImage').animate({
      width: 478, 
      height: 265, 
      marginLeft: 480, 
      marginTop: 0
   }, "slow", "easeOutQuad");

}).mousemove(function(e){
    $("#LocationsMapWrapper #MapImage").each(function(){
        var position = $(this).offset();
        var position_x = position.left;
        var position_y = position.top;
        position_x = 0;
        position_y = 0;
        var windowwidth = ($(window).width()/2);
        var windowheight = ($("#LocationsMapWrapper").height()/2);
        var endX = (windowwidth)-(e.pageX);
        var endY = (windowheight)-(e.pageY);
        var speed = 5;
        position_x += (endX-position_x)/speed;
        position_y += (endY-position_y)/speed;
        $(this).css({'position': 'relative'});
        $(this).css({'left':position_x});
        $(this).css({'top':position_y});
   }); 
}).mouseleave(function(){
   $("#LocationsMapWrapper #MapImage").each(function(){
        $(this).css({'left':0});
        $(this).css({'top':0});
   }); 
});

这里有一些相关的CSS:

/* locations map */
#sectionContent3019160 { width: 100%; height: 0px; margin: auto; opacity: 0.15; margin-bottom: 10px; z-index: 1; overflow: hidden; }
#sectionContent3019160 { margin-top: -48px; } /* up */

#LocationsMapWrapper { width: 1020px; height: 355px; margin: auto; }
#LocationsMapWrapper #MapImage { width: 478px; height: 265px; margin-left: 480px; }

任何帮助表示赞赏!我已经尝试了所有我能想到的方法来让它运行得更顺利,但我却不知所措。请注意,我正在使用托管 CMS 服务,因此我必须修改已建立的 html 布局。

更新: 这是我目前更新的代码:

$('#LocationsMapWrapper').hover(function() {
   $('#LocationsMapWrapper #MapImage').stop().animate({ 
      width: 600,
      height: 375,
      marginLeft: 550,
      marginTop: -20
   }, "slow", "easeOutQuad").mousemove(function(e){
        var position = $(this).offset();
        var position_x = position.left;
        var position_y = position.top;
        position_x = 0;
        position_y = 0;
        var windowwidth = ($(window).width()/2);
        var windowheight = ($("#LocationsMapWrapper").height()/2);
        var endX = (windowwidth)-(e.pageX);
        var endY = (windowheight)-(e.pageY);
        var speed = 5;
        position_x += (endX-position_x)/speed;
        position_y += (endY-position_y)/speed;
        $(this).css({'position': 'relative'});
        $(this).css({'left':position_x});
        $(this).css({'top':position_y});
   });         
}, function() {
   $('#LocationsMapWrapper #MapImage').stop().animate({ 
      width: 478, 
      height: 290, 
      marginLeft: 480, 
      marginTop: 0,
      left: 0,
      top: 0
   }, "slow", "easeOutQuad");
});

~ I've been working on this for a while now (many months!!) -- using jquery to zoom and pan an image map - which is a bit outside my current skill level so I'm excited that I have gotten this far!!~ but the functionality is not as smooth as it needs to be (the zoom in and out needs to be smoother) - and there are some larger issues when viewed in IE7.

Here it is on the webpage: http://www.agencydr.squarespace.com/locations

Below is the jquery used.
Does anyone notice anything I should change?

/* ************************************** */
/* locations map */
/* ************************************** */
$('#modulePage6955407 #sectionContent3019160').insertAfter("#pageHeaderWrapper");
$('#modulePage6955407 #bannerAreaWrapper').animate({"top": "+=250px"}, "slow");
$('#modulePage6955407 #sectionContent3019160').animate({"height": "290px"}, "slow");
$('#modulePage6955407 #sectionContent3019160').animate({"opacity": "1"}, "slow");

$('#LocationsMapWrapper').hover(function() {
   $('#LocationsMapWrapper #MapImage').animate({
      width: 600,
      height: 375,
      marginLeft: 550,
      marginTop: -20
   }, "slow", "easeOutQuad");
 },
 function() {
   $('#LocationsMapWrapper #MapImage').animate({
      width: 478, 
      height: 265, 
      marginLeft: 480, 
      marginTop: 0
   }, "slow", "easeOutQuad");

}).mousemove(function(e){
    $("#LocationsMapWrapper #MapImage").each(function(){
        var position = $(this).offset();
        var position_x = position.left;
        var position_y = position.top;
        position_x = 0;
        position_y = 0;
        var windowwidth = ($(window).width()/2);
        var windowheight = ($("#LocationsMapWrapper").height()/2);
        var endX = (windowwidth)-(e.pageX);
        var endY = (windowheight)-(e.pageY);
        var speed = 5;
        position_x += (endX-position_x)/speed;
        position_y += (endY-position_y)/speed;
        $(this).css({'position': 'relative'});
        $(this).css({'left':position_x});
        $(this).css({'top':position_y});
   }); 
}).mouseleave(function(){
   $("#LocationsMapWrapper #MapImage").each(function(){
        $(this).css({'left':0});
        $(this).css({'top':0});
   }); 
});

and here is some relevant css:

/* locations map */
#sectionContent3019160 { width: 100%; height: 0px; margin: auto; opacity: 0.15; margin-bottom: 10px; z-index: 1; overflow: hidden; }
#sectionContent3019160 { margin-top: -48px; } /* up */

#LocationsMapWrapper { width: 1020px; height: 355px; margin: auto; }
#LocationsMapWrapper #MapImage { width: 478px; height: 265px; margin-left: 480px; }

Any help is appreciated!! I've tried everything I can think of to get this to run more smoothly but am at a loss. Please note that I am using a hosted CMS service so I have to modify a somewhat established html layout.

UPDATE:
Here is my updated code at the moment:

$('#LocationsMapWrapper').hover(function() {
   $('#LocationsMapWrapper #MapImage').stop().animate({ 
      width: 600,
      height: 375,
      marginLeft: 550,
      marginTop: -20
   }, "slow", "easeOutQuad").mousemove(function(e){
        var position = $(this).offset();
        var position_x = position.left;
        var position_y = position.top;
        position_x = 0;
        position_y = 0;
        var windowwidth = ($(window).width()/2);
        var windowheight = ($("#LocationsMapWrapper").height()/2);
        var endX = (windowwidth)-(e.pageX);
        var endY = (windowheight)-(e.pageY);
        var speed = 5;
        position_x += (endX-position_x)/speed;
        position_y += (endY-position_y)/speed;
        $(this).css({'position': 'relative'});
        $(this).css({'left':position_x});
        $(this).css({'top':position_y});
   });         
}, function() {
   $('#LocationsMapWrapper #MapImage').stop().animate({ 
      width: 478, 
      height: 290, 
      marginLeft: 480, 
      marginTop: 0,
      left: 0,
      top: 0
   }, "slow", "easeOutQuad");
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

习ぎ惯性依靠 2024-10-01 03:09:47

只有当鼠标停留在图像上(几乎一动不动)时,您才需要缩放它。您不希望图像仅仅因为偶然的鼠标接触而缩小。

我建议您在鼠标悬停在图像上时启动计时器,该计时器会在大约 250-500 毫秒后调用缩放功能,前提是鼠标在该时间间隔内移动的距离没有超过设定的阈值距离。如果鼠标移动超过阈值距离(编辑:仍在图像上或移出图像时),请终止计时器,以便不会发生缩放。

Only when the mouse lingers, fairly motionless, over the image, do you want to zoom it. You don't want the image to zoom out merely from incidental mouse contact.

I would suggest that you start a timer when the mouse is over the image, which invokes the zoom function some 250-500ms later, provided the mouse hasn't moved more than a set threshold distance in that interval. If the mouse moves more than your threshold distance (edit: while still on the image, or moves off the image), kill the timer so the zoom does not occur.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文