jQuery:按相对值移动元素 [英] jQuery: Move element by relative value

查看:101
本文介绍了jQuery:按相对值移动元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(表示元素的左值): 移动元素的最简单方法是什么-例如(从当前位置开始)向左10像素?

(Meaning an elements left-value): What's the easiest way to move an element - e.g. 10px to the left (from its current position)?

推荐答案

可能是jQuery过度杀伤并设置了margin-left:-10px可以解决问题.

It might be that jQuery is overkill and setting margin-left: -10px will do the trick.

您可以获取元素相对于文档的offset(): http://docs.jquery.com /CSS/偏移量

You can get an element's offset() relative to the document: http://docs.jquery.com/CSS/offset

那会给你左,顶部等等.

That'd give you the left,top,etc.

然后,您可能需要像这样使用css来放置元素.

Then you might have to position the element using the css like so.

 subMenu.css({
            position: 'absolute',
            zIndex: 5000,
            left: left,
            top: top
        });

这篇关于jQuery:按相对值移动元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆