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");
});
4

1 回答 1

0

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.

于 2010-09-16T23:27:58.760 回答