position

Leetcode-35 Search Insert Position

。_饼干妹妹 提交于 2020-01-15 18:47:44
#35. Search Insert Position Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array. Here are few examples. [1,3,5,6] , 5 → 2 [1,3,5,6] , 2 → 1 [1,3,5,6] , 7 → 4 [1,3,5,6] , 0 → 0 题解:因为题目已经给出数组是排序过的,所以直接遍历数组,找到大于或者等于目标值的那个数组元素下标,直接返回即可,如果目标值大于所有数组中的值,则直接返回数组的size即可。 class Solution { public: int searchInsert(vector<int>& nums, int target) { for(int i=0;i<nums.size();i++) { if(nums[i]>=target) { return i; } } return nums.size(); } }; 来源: https://www.cnblogs

Setting X Coordinate from Mouse Location

吃可爱长大的小学妹 提交于 2020-01-15 12:20:38
问题 i have a darkBlueRect rectangle sprite and a copy of the same sprite with a larger scale and a lighter color - lightBlueRect . i'm attempting to shift the location of the lightBlueRect according to the mouse.x location when the mouse is moving over the darkBlueRect . this way if the mouse is on the right of the darkBlueRect than the location of the scaled up lightBlueRect will be on the opposite side and shifted towards the left proportionate to the mouse position and scale. in addition, the

BlockUI positioning on the page not the screen

馋奶兔 提交于 2020-01-15 10:16:33
问题 I have used this plugin before but now the blockui is not positioning correctly on the page. on the screen it's ok like 40% from the top but the problem is with the page . it is scrolling all the way up to the top. if I have a button in the moddle of the page and I click on it to start the blockui the page will scrool back to the top. and I dont know why here is the html: <div class="btn" id="block"> <a href="#"><span>to buy tickets</span></a> </div> <div id="blockmsg"> <a href="#" id="x">

BlockUI positioning on the page not the screen

夙愿已清 提交于 2020-01-15 10:16:08
问题 I have used this plugin before but now the blockui is not positioning correctly on the page. on the screen it's ok like 40% from the top but the problem is with the page . it is scrolling all the way up to the top. if I have a button in the moddle of the page and I click on it to start the blockui the page will scrool back to the top. and I dont know why here is the html: <div class="btn" id="block"> <a href="#"><span>to buy tickets</span></a> </div> <div id="blockmsg"> <a href="#" id="x">

css实现不定宽高的div水平、垂直居中

烈酒焚心 提交于 2020-01-15 08:45:17
一共有三个方案: 1,第一种方案主要使用了 css3中transform 进行元素偏移,效果非常好 这方法功能很强大,也比较灵活,不仅仅局限在实现居中显示。 兼容方面也一样拿IE来做比较,第二种方法IE8以上都能使用。 IE8及IE8以下都会出现问题。 <body> <div id="box"> <div id="content">div被其中的内容撑起宽高</div> </div> </body> body,html { margin:0; width:100%; height:100%; } #box { width:100%; height:100%; background:rgba(0,0,0,0.7); position:relative; } #content{ position:absolute; background:pink; left:50%; top:50%; transform:translateX(-50%) translateY(-50%); -webkit-transform:translateX(-50%) translateY(-50%); } 2,第二种利用 flex 进行布局 很简单几句代码就实现了。可惜IE浏览器并不怎么支持display:flex; <body> <div id="box"> <div id="content"

position 定位

时间秒杀一切 提交于 2020-01-15 07:06:27
position 属性的五个值: static relative fixed absolute sticky absolute 定位 绝对定位的元素的位置相对于最近的已定位父元素,如果元素没有已定位的父元素,那么它的位置相对于<html> h2 { position: absolute ; left: 100 px ; top: 150 px ; } absolute 定位使元素的位置与文档流无关,因此不占据空间。 absolute 定位的元素和其他元素重叠 。 static 定位 HTML元素的默认值,即 没有定位 ,元素出现在正常的流中。 静态定位的元素不会受到 top, bottom, left, right影响 div .static { position: static ; border: 3 px solid #73AD21 ; } fixed 定位 元素的位置相对于浏览器窗口是固定位置。 即使窗口是滚动的它也不会移动 p .pos _ fixed { position: fixed ; top: 30 px ; right: 5 px ; } Fixed定位使元素的位置与文档流无关,因此不占据空间。 Fixed定位的元素和其他元素重叠 relative 定位 相对定位元素的定位是相对其正常位置 。 h2 .pos _ left { position: relative

JavaScript get page coordinates of closest clicked character

对着背影说爱祢 提交于 2020-01-15 05:25:08
问题 I have a div tag with a bunch of text in it. <div>Lots of text in here</div> I am listening for onclick events from the div. I would like to insert a fake text cursor wherever the user clicked in the div. I can easily get what character was clicked with: var sel = window.getSelection(); sel.focusOffset; But I don't know how to get the pixel coordinates of that character. 回答1: The rangy library has a feature that does exactly this - find pixel position of selection. Take a look at this demo:

Swift : How do I find the position(x,y) of a letter in a UILabel?

这一生的挚爱 提交于 2020-01-15 03:46:27
问题 I am trying to find the position of a letter in a labelText . The code in Objective C is NSRange range = [@"Good,Morning" rangeOfString:@","]; NSString *prefix = [@"Good,Morning" substringToIndex:range.location]; CGSize size = [prefix sizeWithFont:[UIFont systemFontOfSize:18]]; CGPoint p = CGPointMake(size.width, 0); NSLog(@"p.x: %f",p.x); NSLog(@"p.y: %f",p.y); Please someone tell me how we write the above code in swift ? I am finding it bit difficult to calculate range of a string . 回答1: I

Shader学习七,UnityCG.cginc

给你一囗甜甜゛ 提交于 2020-01-15 00:47:17
常用的着色器文件:E:\Other\install\Unity_2018.3.13f1\Unity\ Editor\Data\CGIncludes 我的安装路径是这个没有CGIncludes这个文件夹的可能就要去官网下载对应版本的着色器了 常用的文件如下: UnityCG.cginc:包含了最常用的帮助函数,宏和结构体等 UnityShaderVariables.cginc:在编译UnityShader时,会被自动包含进来。包含了许多内置的全局变量,如UNITY_MATRIX_MVP等 Lighting.cginc:包含各种内置的光照模型,如果编写的是SurfaceShader的话会自动包含进来 HLSLSupport.cginc:在编译UnityShader时,会自动包含进来。声明了很多用于跨平台编译的宏和定义 UnityCG.cginc中一些常用的结构体 appdata_base:可用于顶点着色器的输入,包含顶点位置,顶点法线,第一组纹理坐标 appdata_tan:可用于顶点着色器输入,包含顶点位置,顶点切线,顶点法线,第一组纹理坐标 appdata_full:可用于顶点着色器的输入,包含顶点位置,顶点切线,顶点法线,四组(或更多)纹理坐标 appdata_img:可用于顶点着色器的输入,包含顶点位置,第一组纹理坐标 v2f_img:可用于顶点着色器的输出

mysql函数LOCATE、POSITION和INSTR

自古美人都是妖i 提交于 2020-01-14 23:51:11
大家在Mysql中判断某个字段是否包含某个字符串时,都会用这样的语法: SELECT ` column ` FROM ` table ` where ` condition ` like ` % keyword % ’ 事实上,可以使用 locate 和 instr 这两个函数来代替 SELECT ` column ` from ` table ` where locate ( ‘keyword’ , ` condition ` ) > 0 或是 locate 的別名 position SELECT ` column ` from ` table ` where position ( ‘keyword’ IN ` condition ` ) 或是 SELECT ` column ` from ` table ` where instr ( ` condition ` , ‘keyword’ ) > 0 locate、position 和 instr 的差別只是参数的位置不同,同时locate 多一个请始位置的参数外,两者是一样的。 速度上这三个比用 like 稍快了一點。 另附三个函数的说明: INSTR(str,substr) 返回字符串 str 中子字符串的第一个出现位置。这和LOCATE()的双参数形式相同,只是参数的顺序被颠倒。 mysql > SELECT INSTR (