javascript - 使用 jQuery 覆盖内联 CSS 应用了一段时间,然后就消失了。为什么?

标签 javascript jquery html css

我正在尝试更改 top 的内联 CSS 样式,该样式默认由 jQuery 使用 jQuery CSS() 类提供。但它应用了一段时间,然后再次切换到旧的内联 CSS 顶部样式。

为什么会这样?

参见 jsfiddle .

这是我所做的:

<script>
`$(".popbutton").on('click',function(e) {
    var mousex = e.pageX + 20, //Get X coodrinates
    mousey = e.screenY + 20; //Get Y coordinates
    var e = jQuery(this);
    this.timer=setTimeout(function () {
        e.popover("show");     
    },600);
    var menu = $(".popbutton").next(),
    menuWidth = menu.width(), //Find width of tooltip
    menuHeight = menu.height(), //Find height of tooltip
    menuVisY = $(window).height() - mousey, //Distance of element from the bottom of viewport
    heightY=$(this)[0].scrollHeight-(1.2*menuHeight);
    $(menu).css('top','100px');
    });
});`

</script>

最佳答案

因为这段代码:

this.timer = setTimeout(function () {
        e.popover("show");
    }, 600);

当您点击按钮时,位置计算正确,但 e.popover('show') 在延迟 600 毫秒后再次更改位置。

关于javascript - 使用 jQuery 覆盖内联 CSS 应用了一段时间,然后就消失了。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23380470/

相关文章:

jQuery 按键 CTRL+S 事件在 Chrome 上不起作用?

html - CSS使用文件上传

javascript - 选择具有空属性或未指定属性的元素

javascript - 不断收到未捕获的语法错误 : unexpected identifier

javascript - JQuery 点击并输入 keyup,不同的类

javascript - 嵌套 if 语句的编程逻辑

Javascript 窗口对象

javascript - 如何从日期选择器验证行中的 3 个日期

jquery - 编写一个新的 jQuery 插件

javascript - 当最后一项在 javascript 的轮播中可见时如何禁用链接/按钮/等