position

Determine touch position on tablets with JavaScript

梦想的初衷 提交于 2020-05-15 07:53:13
问题 I have an object with the name "element". If somebody touches the tablet, I would like to return the x and y coordinates of the touch position relative to the object, i. e. the upper left corner of the object has the coordinates x=0 and y=0. I know how to implement this on desktops: $(function() { $(document).mousedown(function(e) { var offset = $("#element").offset(); var relativeX = (e.pageX - offset.left); var relativeY = (e.pageY - offset.top); alert(relativeX+':'+relativeY); $(".position

How do I display the the index of a list element in Python? [duplicate]

时光总嘲笑我的痴心妄想 提交于 2020-05-14 14:37:38
问题 This question already has answers here : Accessing the index in 'for' loops? (20 answers) Closed 4 years ago . I have a homework assignment. I've got the following code hey = ["lol", "hey","water","pepsi","jam"] for item in hey: print(item) Do I display the position in the list before the item, like this: 1 lol 2 hey 3 water 4 pepsi 5 jam 回答1: The best method to solve this problem is to enumerate the list, which will give you a tuple that contains the index and the item. Using enumerate ,

How do I display the the index of a list element in Python? [duplicate]

强颜欢笑 提交于 2020-05-14 14:36:14
问题 This question already has answers here : Accessing the index in 'for' loops? (20 answers) Closed 4 years ago . I have a homework assignment. I've got the following code hey = ["lol", "hey","water","pepsi","jam"] for item in hey: print(item) Do I display the position in the list before the item, like this: 1 lol 2 hey 3 water 4 pepsi 5 jam 回答1: The best method to solve this problem is to enumerate the list, which will give you a tuple that contains the index and the item. Using enumerate ,

CSS borders interfering with absolute positioning

ぃ、小莉子 提交于 2020-05-12 11:23:30
问题 [edit: clarified that box-sizing: border-box doesn't seem applicable, since I'm using absolute positioning] The following code illustrates my problem. I'm using absolute positioning, because I found this even trickier with flow-based layout, but I'm open to suggestions. What I want is borders around arbitrary elements, without the borders affecting the positioning of the nodes. (The borders may clip or be overwritten by the content, but that doesn't matter.) In particular, the borders of a

Konvajs: How to change position of group of texts

我是研究僧i 提交于 2020-04-30 06:25:04
问题 I'm using Konvajs, I have group of texts, and I want don't allow drag group outside of the canvas, I'm tried solved that using dragBoundFunc, but that don't help me, now I just try change group position during dragmove, but setPosition, setAbsloutePosition, nothing allow me to change group position stage.on('dragmove', (e) => stageOnDragMove(e, layer)); const stageOnDragMove = (e: Konva.KonvaEventObject<any>, layer: Konva.Layer) => { const selectionGroup = layer.findOne('#selection-group');

关于 IOS5 使用 position:fixed 与 scrollTo 共存的 bug

六眼飞鱼酱① 提交于 2020-04-22 05:21:07
这两天帮某个项目处理后事,本以为可以轻松搞定,不成想又发现了一个bug..... 背景描述: ios5 提出了支持 position:fixed ,于是乎大家觉得让浮动的图层固定在屏幕最下方容易多了,赶紧用上吧。可是呢。。。页面上又有好多地方需要用到 scrollTo 控制滚动条移动,尤其是页面刚加载完毕需要让浏览器默认的 url 栏消失,一般都用 scrollTo(0,0) 或 scrollTo(0,1) 之类的。。。当这两者混合时就出现问题了, 浮动的div 虽然是你看到的在最下方,但是实际上这个div 内的触控点全都漂移了。 (画外音:通过这件事情,我们明白了一个道理:不能只相信你的眼睛....) 用 iphone 访问地址: http://ztree.me/issueTest/iosFixed.html (注意,此 bug 在 iphone5上不存在!应该是 ios6 系统修正了这个bug。 ) 你就可以重现上图的问题,看触屏的位置,那里没有任何内容,但是点击后会看到灰色阴影,点击后 alert 44,这说明 click 44 这个 li 的位置实际上漂移到了那里。 bug 描述: 通过这个 Demo 可以基本确定 bug 的原因——利用 scrollTo 滚屏时,会导致 position:fixed 的图层视图不变,但对应的 DOM 实际响应位置却跟随 滚动条一起移动了

css定位-position

二次信任 提交于 2020-04-08 08:32:56
css定位 定位模式:在css中,position属性用于定义元素的定位模式,其基本语法格式如下:选择器{position:属性值;} position属性值有5种,分别是静态定位,相对定位,绝对定位,固定定位和粘性定位 属性值 描述 static(静态定位) 正常显示,和不设置的效果一样 absolute(绝对定位) 以已定位父元素的位置为参照物,脱离文档流,不占据空间 relative(相对定位) 以自身默认的位置为参照物;不会破坏正常的布局流;占据空间 fixed(固定定位) 以浏览器的窗口为参照物;不论窗口滚动与否,元素都会留在那个位置 stick(粘性定位) 当元素在屏幕内,表现为relative;滚出显示器屏幕时,表现为fixed 偏移属性 定位模式仅仅定义了以哪种方式进行定位,并不能确定元素的具体位置,在css中,通过偏移属性来定义位置,其取值为数值或百分比。 偏移属性 描述 top 顶端偏移量,定义元素相对于其参照物的上边线的距离 bottom 底部偏移量,定义元素相对于其参照物的下边线的距离 left 左侧偏移量,定义元素相对于其参照物的左边线的距离 right 右侧偏移量,定义元素相对于其参照物的右边线的距离 注意: 在静态定位下,left,top属性不起作用 包含块 包含块是绝对定位的基础,包含块就是为定位元素提供坐标,偏移和显示范围的参照物

理解 CSS 的 z-index 属性

血红的双手。 提交于 2020-04-08 06:42:40
通常认为HTML页面是二维的,但实际上,CSS还有一个 z-index 属性,允许层叠元素。 所有的盒模型元素都处于三维坐标系中。 除了我们常用的横坐标和纵坐标, 盒模型元素还可以沿着“z轴”层叠摆放, 当他们相互覆盖时, z轴顺序就变得十分重要。 -- CSS 2.1 Section 9.9.1 - Layered presentation 默认的摆放规则 假定元素没有指定 z-index 属性,那么元素按照如下顺序叠放(从底到顶) 根元素的背景和边界 普通流(无定位)里的块元素(没有position或者position:static;)按HTML中的出现顺序堆叠 定位元素按HTML中的出现顺序堆叠 浮动 对于浮动的块元素来说,堆叠顺序变得有些不同。浮动块元素被放置于非定位块元素与定位块元素之间: 根元素的背景与边框 位于普通流中的后代块元素按照它们在 HTML 中出现的顺序堆叠 浮动块元素 常规流中的后代行内元素 后代中的定位元素按照它们在 HTML 中出现的顺序堆叠 使用 z-index 如果需要改变默认的摆放顺序,只需给元素指定 z-index 。 z-index 必须是整数,体现了元素在z轴的位置: 底层:距离观察者最远 …… -3 层 -2 层 -1 层 0 层 (默认) 1 层 2 层 3 层 …… 顶层:最接近观察者 没有指定 z-index 的时候

Unity之Animation动画

我们两清 提交于 2020-04-08 06:33:16
Unity之Animation绘制动画 这篇文章做最简单的动画,让一个立方体从左边移动到右边。 1.创建一个Unity的新工程,名为TestAnimation,点击Create And Open按键,打开工程。 2.进入工程之后,点击File->Save Scene。 点击之后会弹出一个文本框,在文件名处输入testAnimation,点击保存按钮。在Project处就可以看到testAnimation的产生。 3.在Hierarchy中点击右键,选择3D Project->Cube。 在Scene中出现Cube。 4.点击Hierarchy中的Cube,在Inspector窗口中出现Cube所有的组件,点击Add Component,搜索Animation,选择Animation。 Cube就多了Animation组件 Animation组件参数解析: Animation:默认的动画; Animations:所有的组件, Size:组件的个数; Element X:组件; Play Automatically:是否在开始的时候自动播放默认的动画; Animate Physics:如果打开这个选项,动画会在物理循环过程中被执行,只有在结合运动学刚体的时候才有用。 Culling Type:Based On Renderers:当渲染不可见时,动画被禁用。 Always

设计模式-组合模式

╄→гoц情女王★ 提交于 2020-04-07 07:50:07
组合模式(Composite Pattern)也叫合成模式,有时又叫做部分-整体模式(Part-Whole), 主要是用来描述部分与整体的关系: 定义: Compose objects into tree structures to represent part-whole hierarchies.Composite lets clients treat individual objects and compositions of objects uniformly.(将对象组合成树形结构以表示“部分-整体”的层次结构,使得用户对单个对象和组合对象的使用具有一致性。) 举个最常见的例子,公司组织架构就是一个典型的树状结构(网上截取图): image.png 我们一般会这样设计组织架构,看代码实现 首先根节点IROOT /** * 根节点 * @author shuliangzhao * @Title: IRoot * @ProjectName design-parent * @Description: TODO * @date 2019/6/18 22:37 */ public interface IRoot { //得到总经理的信息 public String getInfo(); //总经理下边要有小兵,那要能增加小兵,比如研发部总经理,这是个树枝节点 public void