【问题标题】:jQuery get image position after rotationjQuery在旋转后获取图像位置
【发布时间】:2013-11-19 22:41:13
【问题描述】:

我有一个 javascript 函数,它可以像轮播一样旋转一组图像,因此为每个更新间隔的每个图像设置一个绝对位置。

效果很好。

当点击图片时,它会被带到前面。这可能需要 2-3 秒,具体取决于图像的数量。

旋转完成后,需要确定前图像的位置(css - left 和 top 属性值。

这里的问题是当我这样做时

    $('.rotatableImage').click(function() {
        $(this).parent().append("<div style='position: absolute; left: " + $(this).css('left') + "; top: " + $(this).css('top') + ";'>Text</div>");
    });  

在旋转完成之前单击时,我会立即获得左侧和顶部的位置。

有没有办法在不使用 jquery 或 javascript 进行修改的情况下解决这个问题?

我也尝试了一些 SetTimeout,但这也立即绑定了点击,我得到了错误的值。

【问题讨论】:

  • 轮换码在哪里?

标签: jquery rotation position delay


【解决方案1】:

轮换代码在这里@john Smith item 是 var Item = function(img, opt) cotaint img 对象属性

var style;
var px = 'px';  
var context = this;

for (var i = 0; i<itemsLen ;i++)
{
   item = items[i];

   sinVal = funcSin(radians);

   scale = ((sinVal+1) * smallRange) + minScale;

   x = this.xCentre + (( (funcCos(radians) * this.xRadius) - (item.orgWidth*0.5)) * scale);
   y = this.yCentre + (( (sinVal * this.yRadius)  ) * scale);       

   if (item.imageOK)
   {
       var  img = item.image;
       w = img.width = item.orgWidth * scale;                   
       h = img.height = item.orgHeight * scale;


       img.style.left = x + px ;
       img.style.top = y + px;
       img.style.zIndex = "" + (scale *100)>>0;                                     
   }
   radians += spacing;
}

 this.innerWrapper.style.display = 'block';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-08
    • 1970-01-01
    相关资源
    最近更新 更多