无法更改此 JavaScript 以在 mousemove 上读取高度小于宽度

发布于 2024-08-12 05:14:00 字数 1725 浏览 10 评论 0原文

所以我试图设置这个 jQuery CSS 停靠栏菜单,您可以在设置中输入附近​​内容。接近程度决定了何时触发缩放,但您只能输入一个距离——高度和宽度相同。我如何更改此代码以允许输入一个高度和一个宽度 -或者 - 我怎样才能只输入一个值,但将垂直值切成两半?任何一个都有效...这是我认为需要更改的代码...如果您需要整个事情,请告诉我,我将发布其余部分有

jQuery(document).bind('mousemove', function(e) {
  var pointer = jQuery.iUtil.getPointer(e);
  var toAdd = 0;

  if (el.fisheyeCfg.halign && el.fisheyeCfg.halign == 'center') 
    var posx = pointer.x - el.fisheyeCfg.pos.x 
               - (el.offsetWidth - el.fisheyeCfg.itemWidth * el.fisheyeCfg.items.size())
               / 2 - el.fisheyeCfg.itemWidth / 2;
  else if (el.fisheyeCfg.halign && el.fisheyeCfg.halign == 'right') 
    var posx = pointer.x - el.fisheyeCfg.pos.x - el.offsetWidth 
               + el.fisheyeCfg.itemWidth * el.fisheyeCfg.items.size();
  else 
    var posx = pointer.x - el.fisheyeCfg.pos.x;

  var posy = Math.pow(pointer.y - el.fisheyeCfg.pos.y - el.offsetHeight / 2, 2);

  el.fisheyeCfg.items.each(function(nr) {
    distance = Math.sqrt(Math.pow(posx - nr * el.fisheyeCfg.itemWidth, 2) + posy);
    distance -= el.fisheyeCfg.itemWidth / 2;
    distance = distance < 0 ? 0 : distance;
    distance = distance > el.fisheyeCfg.proximity ? el.fisheyeCfg.proximity : distance;
    distance = el.fisheyeCfg.proximity - distance;
    extraWidth = el.fisheyeCfg.maxWidth * distance / el.fisheyeCfg.proximity;
    this.style.width = el.fisheyeCfg.itemWidth + extraWidth + 'px';
    this.style.left = el.fisheyeCfg.itemWidth * nr + toAdd + 'px';
    toAdd += extraWidth;
  });
  jQuery.iFisheye.positionContainer(el, toAdd);
});

任何想法吗?

谢谢,
马特

So I'm trying to set up this jQuery CSS dock menu and you can enter in a proximity in the setup. The proximity determines when the zoom will be triggered, but you only get to put in one distance -- same for height and width. How can I change this code to allow to enter in a single one for height and a single one for width -OR- how can I just have one value entered in but have the vertical one cut in half? either one works... here's the bit of code that I think needs to be changed... if you need the whole thing let me know and I'll post the rest of it

jQuery(document).bind('mousemove', function(e) {
  var pointer = jQuery.iUtil.getPointer(e);
  var toAdd = 0;

  if (el.fisheyeCfg.halign && el.fisheyeCfg.halign == 'center') 
    var posx = pointer.x - el.fisheyeCfg.pos.x 
               - (el.offsetWidth - el.fisheyeCfg.itemWidth * el.fisheyeCfg.items.size())
               / 2 - el.fisheyeCfg.itemWidth / 2;
  else if (el.fisheyeCfg.halign && el.fisheyeCfg.halign == 'right') 
    var posx = pointer.x - el.fisheyeCfg.pos.x - el.offsetWidth 
               + el.fisheyeCfg.itemWidth * el.fisheyeCfg.items.size();
  else 
    var posx = pointer.x - el.fisheyeCfg.pos.x;

  var posy = Math.pow(pointer.y - el.fisheyeCfg.pos.y - el.offsetHeight / 2, 2);

  el.fisheyeCfg.items.each(function(nr) {
    distance = Math.sqrt(Math.pow(posx - nr * el.fisheyeCfg.itemWidth, 2) + posy);
    distance -= el.fisheyeCfg.itemWidth / 2;
    distance = distance < 0 ? 0 : distance;
    distance = distance > el.fisheyeCfg.proximity ? el.fisheyeCfg.proximity : distance;
    distance = el.fisheyeCfg.proximity - distance;
    extraWidth = el.fisheyeCfg.maxWidth * distance / el.fisheyeCfg.proximity;
    this.style.width = el.fisheyeCfg.itemWidth + extraWidth + 'px';
    this.style.left = el.fisheyeCfg.itemWidth * nr + toAdd + 'px';
    toAdd += extraWidth;
  });
  jQuery.iFisheye.positionContainer(el, toAdd);
});

Any ideas?

Thanks,
Matt

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

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

发布评论

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

评论(1

七度光 2024-08-19 05:14:00

我对剧本进行了一番修改,最终修改的内容比我计划的要多一些。

您现在需要使用一些新参数调用脚本:itemHeightproximityXproximityY

$(document).ready(function() {
 $('#fisheye').Fisheye({
  maxWidth: 90,
  items: 'a',
  itemsText: 'span',
  container: '.fisheyeContainter',
  itemWidth: 40,
  itemHeight: 40,
  proximityX: 90,
  proximityY: 10,
  halign : 'center'
 })
});

我没有缩小它,但这里是修改后的插件完整:

/**
 * Interface Elements for jQuery
 * Fisheye menu
 * 
 * http://interface.eyecon.ro
 * 
 * Copyright (c) 2006 Stefan Petre
 * Dual licensed under the MIT (MIT-LICENSE.txt) 
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 */

/**
 * Build a Fisheye menu from a list of links
 *
 * @name Fisheye
 * @description Build a Fisheye menu from a list of links
 * @param Hash hash A hash of parameters
 * @option String items items selection
 * @option String container container element
 * @option Integer itemWidth the minimum width for each item
 * @option Integer maxWidth the maximum width for each item
 * @option String itemsText selection of element that contains the text for each item
 * @option Integer proximity the distance from element that make item to interact
 * @option String valign vertical alignment
 * @option String halign horizontal alignment
 *
 * @type jQuery
 * @cat Plugins/Interface
 * @author Stefan Petre
 */
jQuery.iFisheye = {

 build : function(options)
 {

  return this.each(
   function()
   {
    var el = this;
    el.fisheyeCfg = {
     items : jQuery(options.items, this),
     container: jQuery(options.container, this),
     pos : jQuery.iUtil.getPosition(this),
     itemWidth: options.itemWidth,
     itemHeight: options.itemHeight,
     itemsText: options.itemsText,
     proximityX: options.proximityX,
     proximityY: options.proximityY,
     valign: options.valign,
     halign: options.halign,
     maxWidth : options.maxWidth
    };
    jQuery.iFisheye.positionContainer(el, 0);
    jQuery(window).bind(
     'resize',
     function()
     {
      el.fisheyeCfg.pos = jQuery.iUtil.getPosition(el);
      jQuery.iFisheye.positionContainer(el, 0);
      jQuery.iFisheye.positionItems(el);
     }
    );
    jQuery.iFisheye.positionItems(el);
    el.fisheyeCfg.items
     .bind(
      'mouseover',
      function()
      {
       jQuery(el.fisheyeCfg.itemsText, this).get(0).style.display = 'block';
      }
     )
     .bind(
      'mouseout',
      function()
      {
       jQuery(el.fisheyeCfg.itemsText, this).get(0).style.display = 'none';
      }
     );
    jQuery(document).bind(
     'mousemove',
     function(e)
     {
      var pointer = jQuery.iUtil.getPointer(e);
      var toAdd = 0;
      if (el.fisheyeCfg.halign && el.fisheyeCfg.halign == 'center')
       var posx = pointer.x - el.fisheyeCfg.pos.x - (el.offsetWidth - el.fisheyeCfg.itemWidth * el.fisheyeCfg.items.size())/2 - el.fisheyeCfg.itemWidth/2;
      else if (el.fisheyeCfg.halign && el.fisheyeCfg.halign == 'right')
       var posx = pointer.x - el.fisheyeCfg.pos.x - el.offsetWidth + el.fisheyeCfg.itemWidth * el.fisheyeCfg.items.size();
      else 
       var posx = pointer.x - el.fisheyeCfg.pos.x;
      var posy = Math.pow(pointer.y - el.fisheyeCfg.pos.y - el.offsetHeight + el.fisheyeCfg.itemHeight,2);
      el.fisheyeCfg.items.each(
       function(nr)
       {
        distanceX = Math.sqrt(
         Math.pow(posx - nr*el.fisheyeCfg.itemWidth, 2)
        );
        distanceY = Math.sqrt(posy) - el.fisheyeCfg.itemHeight;
        distanceX -= el.fisheyeCfg.itemWidth/2;
        distanceX = distanceX < 0 ? 0 : distanceX;
        distanceX = distanceX > el.fisheyeCfg.proximityX ? el.fisheyeCfg.proximityX : distanceX;
        distanceX = el.fisheyeCfg.proximityX - distanceX;
        distanceY = distanceY > el.fisheyeCfg.proximityY ? el.fisheyeCfg.proximityY : distanceY;
        distanceY = el.fisheyeCfg.proximityY - distanceY;
        extraWidth = el.fisheyeCfg.maxWidth/4 * (distanceX*distanceY)/(el.fisheyeCfg.proximityX*el.fisheyeCfg.proximityY); // divided by 4 to smooth the sizing transition
        extraWidth = (extraWidth > el.fisheyeCfg.maxWidth) ? el.fisheyeCfg.maxWidth : extraWidth;
        this.style.width = el.fisheyeCfg.itemWidth + extraWidth + 'px';
        this.style.left = el.fisheyeCfg.itemWidth * nr + toAdd + 'px';
        toAdd += extraWidth;
       }
      );
      jQuery.iFisheye.positionContainer(el, toAdd);
     }
    );
   }
  )
 },

 positionContainer : function(el, toAdd)
 {
  if (el.fisheyeCfg.halign)
   if (el.fisheyeCfg.halign == 'center')
    el.fisheyeCfg.container.get(0).style.left = (el.offsetWidth - el.fisheyeCfg.itemWidth * el.fisheyeCfg.items.size())/2 - toAdd/2 + 'px';
   else if (el.fisheyeCfg.halign == 'left')
    el.fisheyeCfg.container.get(0).style.left =  - toAdd/el.fisheyeCfg.items.size() + 'px';
   else if (el.fisheyeCfg.halign == 'right')
    el.fisheyeCfg.container.get(0).style.left =  (el.offsetWidth - el.fisheyeCfg.itemWidth * el.fisheyeCfg.items.size()) - toAdd/2 + 'px';
  el.fisheyeCfg.container.get(0).style.width = el.fisheyeCfg.itemWidth * el.fisheyeCfg.items.size() + toAdd + 'px';
 },

 positionItems : function(el)
 {
  el.fisheyeCfg.items.each(
   function(nr)
   {
    this.style.width = el.fisheyeCfg.itemWidth + 'px';
    this.style.left = el.fisheyeCfg.itemWidth * nr + 'px';
   }
  );
 }
};

jQuery.fn.Fisheye = jQuery.iFisheye.build;

I messed around with the script and ended up changing it a bit more than I planned.

You will now need to call the script using a few new parameters: itemHeight, proximityX and proximityY

$(document).ready(function() {
 $('#fisheye').Fisheye({
  maxWidth: 90,
  items: 'a',
  itemsText: 'span',
  container: '.fisheyeContainter',
  itemWidth: 40,
  itemHeight: 40,
  proximityX: 90,
  proximityY: 10,
  halign : 'center'
 })
});

I didn't minify it, but here is the modified plugin in full:

/**
 * Interface Elements for jQuery
 * Fisheye menu
 * 
 * http://interface.eyecon.ro
 * 
 * Copyright (c) 2006 Stefan Petre
 * Dual licensed under the MIT (MIT-LICENSE.txt) 
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 */

/**
 * Build a Fisheye menu from a list of links
 *
 * @name Fisheye
 * @description Build a Fisheye menu from a list of links
 * @param Hash hash A hash of parameters
 * @option String items items selection
 * @option String container container element
 * @option Integer itemWidth the minimum width for each item
 * @option Integer maxWidth the maximum width for each item
 * @option String itemsText selection of element that contains the text for each item
 * @option Integer proximity the distance from element that make item to interact
 * @option String valign vertical alignment
 * @option String halign horizontal alignment
 *
 * @type jQuery
 * @cat Plugins/Interface
 * @author Stefan Petre
 */
jQuery.iFisheye = {

 build : function(options)
 {

  return this.each(
   function()
   {
    var el = this;
    el.fisheyeCfg = {
     items : jQuery(options.items, this),
     container: jQuery(options.container, this),
     pos : jQuery.iUtil.getPosition(this),
     itemWidth: options.itemWidth,
     itemHeight: options.itemHeight,
     itemsText: options.itemsText,
     proximityX: options.proximityX,
     proximityY: options.proximityY,
     valign: options.valign,
     halign: options.halign,
     maxWidth : options.maxWidth
    };
    jQuery.iFisheye.positionContainer(el, 0);
    jQuery(window).bind(
     'resize',
     function()
     {
      el.fisheyeCfg.pos = jQuery.iUtil.getPosition(el);
      jQuery.iFisheye.positionContainer(el, 0);
      jQuery.iFisheye.positionItems(el);
     }
    );
    jQuery.iFisheye.positionItems(el);
    el.fisheyeCfg.items
     .bind(
      'mouseover',
      function()
      {
       jQuery(el.fisheyeCfg.itemsText, this).get(0).style.display = 'block';
      }
     )
     .bind(
      'mouseout',
      function()
      {
       jQuery(el.fisheyeCfg.itemsText, this).get(0).style.display = 'none';
      }
     );
    jQuery(document).bind(
     'mousemove',
     function(e)
     {
      var pointer = jQuery.iUtil.getPointer(e);
      var toAdd = 0;
      if (el.fisheyeCfg.halign && el.fisheyeCfg.halign == 'center')
       var posx = pointer.x - el.fisheyeCfg.pos.x - (el.offsetWidth - el.fisheyeCfg.itemWidth * el.fisheyeCfg.items.size())/2 - el.fisheyeCfg.itemWidth/2;
      else if (el.fisheyeCfg.halign && el.fisheyeCfg.halign == 'right')
       var posx = pointer.x - el.fisheyeCfg.pos.x - el.offsetWidth + el.fisheyeCfg.itemWidth * el.fisheyeCfg.items.size();
      else 
       var posx = pointer.x - el.fisheyeCfg.pos.x;
      var posy = Math.pow(pointer.y - el.fisheyeCfg.pos.y - el.offsetHeight + el.fisheyeCfg.itemHeight,2);
      el.fisheyeCfg.items.each(
       function(nr)
       {
        distanceX = Math.sqrt(
         Math.pow(posx - nr*el.fisheyeCfg.itemWidth, 2)
        );
        distanceY = Math.sqrt(posy) - el.fisheyeCfg.itemHeight;
        distanceX -= el.fisheyeCfg.itemWidth/2;
        distanceX = distanceX < 0 ? 0 : distanceX;
        distanceX = distanceX > el.fisheyeCfg.proximityX ? el.fisheyeCfg.proximityX : distanceX;
        distanceX = el.fisheyeCfg.proximityX - distanceX;
        distanceY = distanceY > el.fisheyeCfg.proximityY ? el.fisheyeCfg.proximityY : distanceY;
        distanceY = el.fisheyeCfg.proximityY - distanceY;
        extraWidth = el.fisheyeCfg.maxWidth/4 * (distanceX*distanceY)/(el.fisheyeCfg.proximityX*el.fisheyeCfg.proximityY); // divided by 4 to smooth the sizing transition
        extraWidth = (extraWidth > el.fisheyeCfg.maxWidth) ? el.fisheyeCfg.maxWidth : extraWidth;
        this.style.width = el.fisheyeCfg.itemWidth + extraWidth + 'px';
        this.style.left = el.fisheyeCfg.itemWidth * nr + toAdd + 'px';
        toAdd += extraWidth;
       }
      );
      jQuery.iFisheye.positionContainer(el, toAdd);
     }
    );
   }
  )
 },

 positionContainer : function(el, toAdd)
 {
  if (el.fisheyeCfg.halign)
   if (el.fisheyeCfg.halign == 'center')
    el.fisheyeCfg.container.get(0).style.left = (el.offsetWidth - el.fisheyeCfg.itemWidth * el.fisheyeCfg.items.size())/2 - toAdd/2 + 'px';
   else if (el.fisheyeCfg.halign == 'left')
    el.fisheyeCfg.container.get(0).style.left =  - toAdd/el.fisheyeCfg.items.size() + 'px';
   else if (el.fisheyeCfg.halign == 'right')
    el.fisheyeCfg.container.get(0).style.left =  (el.offsetWidth - el.fisheyeCfg.itemWidth * el.fisheyeCfg.items.size()) - toAdd/2 + 'px';
  el.fisheyeCfg.container.get(0).style.width = el.fisheyeCfg.itemWidth * el.fisheyeCfg.items.size() + toAdd + 'px';
 },

 positionItems : function(el)
 {
  el.fisheyeCfg.items.each(
   function(nr)
   {
    this.style.width = el.fisheyeCfg.itemWidth + 'px';
    this.style.left = el.fisheyeCfg.itemWidth * nr + 'px';
   }
  );
 }
};

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