jquery - e.pageX 在所有分辨率下都无法正常工作

标签 jquery html css

onClick a span,我必须在那个位置显示一条消息。所以我使用 e.pageX 来确定鼠标点击位置,因为可能有两个以上的跨度。它在决议中工作正常。如果我最大化分辨率,则消息显示在远离点击范围的地方。

$('div.moveRemoveItems').on('click','.detailRowThree #itemRawHerb',function(e) {
    e.preventDefault();
    $('div#viewboxCR').css( 'left', e.pageX+30 );
    $('div#viewboxCR').show();
    $('div#viewboxCR').css('z-index','999');
}

最佳答案

您应该在此 html 模型中设置 css 属性:

<div class="parent">
    <div class="child">
    </div>
</div>

所以css属性应该是

.parent{
position: fixed;
width: 100%;
height: 100%
top: 0;
left: 0;
}

.child{
position: relative;
width: 200px;
margin: auto;
}

所以它应该可以工作。不过你可以使用 jquery 方法 .resize(),像这样:

$(window).on('resize', function() {
    // your diffirent code here for calcaulating parametrs 
});

如果我没看错的话。

关于jquery - e.pageX 在所有分辨率下都无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24651804/

相关文章:

javascript - 为什么模拟点击提交不起作用

javascript - AngularJS 指令 transclude scope=false?

css - 使用@font-face 重新分配字体

html - header 拉伸(stretch)太远

html - 溢出 :hidden showing pseudo element

jquery - AngularJS - 可拖动和多个连接的可排序(jQuery UI + Angular-Common)

javascript - 根据 slider 值显示和隐藏元素

javascript - 双击以编辑 Meteor 应用程序中的元素

css - Firefox CSS3 等腰三 Angular 形渲染问题

javascript - Jasmine 测试未检测到 jQuery 国际化常量