jquery - 如何将 div 放置在屏幕外并将其重新悬停

标签 jquery html css position

这是我正在使用的代码的 fiddle :FIDDLE ,由于重叠错误阻止 a.trigger 在 IE 中工作,我需要将 div.pop-up 定位在屏幕之外,直到 a.trigger 悬停在上面。

谁知道怎么做

最佳答案

这里有一些老派的技巧。您只需将元素定位到屏幕左侧 1000 像素,然后在您制作动画之前将其放回:

$(document).ready(function() {
    //If Javascript is running, change css on product-description to display:block
    //then hide the div, ready to animate
    $("div.pop-up").css({'display':'block','opacity':'0'})

    $("a.trigger").hover(
      function () {
        $(this).prev().css("left", "0px");
        $(this).prev().stop().animate({
          opacity: 1
        }, 500);
      },
      function () {
        // First answer had this line coming first.
        // $(this).prev().css("left", "-1000px");
        $(this).prev().stop().animate({
          opacity: 0
        }, 200);
        // It should actually probably be here
        // so the movement is still done invisibly
        $(this).prev().css("left", "-1000px");
      }
    )
  });​

您还需要在 css 中将定位添加到左侧。

/* HOVER STYLES */
div.pop-up {
  /*display: none;*/
  text-align: left;
  position: absolute;
  left: -1000px;      // <--- Send me left
  margin-top: -10px;
  width: 120px;
  padding: 0px 13px;
  background: #eeeeee;
  color: #000000;
  border: 1px solid #1a1a1a;
  font-size: 90%;
}

看我的实际操作 -> JSFiddle

关于jquery - 如何将 div 放置在屏幕外并将其重新悬停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11450659/

相关文章:

jquery模板引擎,如何绑定(bind)事件

html - 如何将导航栏放置在页面的更上方?

javascript - 通过路线更新 View 时的 ng-animate

Jquery 代码在不应该返回 true 时返回

jquery - jQuery .first() 和 .last() 的工作方式不同吗?

javascript - 我需要一个转换器来制作任何 jquery 代码以制作 no.conflict 模式?

html - 移动设备上的 Bootstrap 4 sidenav 不在左侧

html - 如何在行布局和全宽中组织我的按钮

css - 什么 CSS 属性控制着这个输入突出显示?

html - 不居中向右滑出列表项