Is there a workaround for IE 6/7 “Unspecified Error” bug when accessing offsetParent

前端 未结 6 1895
一个人的身影
一个人的身影 2020-12-29 15:45

I\'m using jQuery UI\'s draggable and droppable libraries in a simple ASP.NET proof of concept application. This page uses the ASP.NET AJAX UpdatePanel to do partial page up

6条回答
  •  有刺的猬
    2020-12-29 16:20

    My version is:

    1. Add function:

      function getOffsetSum(elem) {
          var top = 0, left = 0
          while (elem) {
              top = top + parseInt(elem.offsetTop)
              left = left + parseInt(elem.offsetLeft)
              try {
                  elem = elem.offsetParent
              }
              catch (e) {
                  return { top: top, left: left }
              }
          }
          return { top: top, left: left }
      };
      
    2. replace

      var box  = this[0].getBoundingClientRect()
      

      with

      var box = getOffsetSum(this[0])
      

    PS: jquery-1.3.2.

提交回复
热议问题