小编Mac*_*Elf的帖子

Python字符串切片索引 - 切片到字符串的结尾

使用字符串索引,有没有办法切片到字符串结尾而不使用len()?负指数从结尾开始,但[-1]省略了最终字符.

word = "Help"
word[1:-1] # But I want to grab up to end of string!
word[1:len(word)] # Works but is there anything better?
Run Code Online (Sandbox Code Playgroud)

python string

24
推荐指数
3
解决办法
6万
查看次数

在javascript中选择最丰富多彩的颜色

我有一组颜色,我想找到他们相对的色彩.任何人都可以在javascript中向我展示一个例子吗?非常感谢!

javascript colors

7
推荐指数
1
解决办法
274
查看次数

谷歌货币转换器API - 它会关闭iGoogle吗?

iGoogle正在关闭.

有一个(未记录的?)货币转换API可用于以下网址:http://www.google.com/ig/calculator?hl = en&q = 1GBP =? USD

此网址的基础 - google.com/ig-将您带到iGoogle.iGoogle关闭后API是否可用?

currency igoogle

7
推荐指数
2
解决办法
3万
查看次数

作为参数传递给函数的jQuery对象是值复制而不是引用?

我的理解:在Javascript对象和数组中作为引用而不是函数参数的值传递.jQuery组是一个对象,因此应该作为参考传递.

但是我在下面的测试脚本中发现了一些奇怪的事情; jQuery组的行为就像一个值而不是引用,除非包装在另一个对象中...任何人都可以解释这个吗?

<html>
<head>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<script>

 function test(arg){
   arg = arg.add($('<span/>'))
   console.log(arg);
 };

 ele = $('<div/>');
 test(ele);  // div + span in the group as expected
 console.log(ele); // only the div - the 'arg' param in function was a copy

 function test2(arg){
   arg.a = arg.a.add($('<span/>'));
   console.log(arg.a);
 };

 obj = {a:ele};
 test2(obj); // div + span in the group as expected
 console.log(obj.a); // both in the group - arg acted like a reference!

</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

javascript jquery

6
推荐指数
1
解决办法
5110
查看次数

计算初始速度以使惯性移动设定距离

我想移动一定距离.但是在我的系统中存在惯性/拖动/负加速.我正在使用这样的简单计算:

v = oldV + ((targetV - oldV) * inertia)
Run Code Online (Sandbox Code Playgroud)

将其应用于多个帧会使运动"上升"或衰减,例如:

v = 10 + ((0 - 10) * 0.25) = 7.5 // velocity changes from 10 to 7.5 this frame
Run Code Online (Sandbox Code Playgroud)

所以我知道我想要旅行的距离和加速度,但不知道能让我到达那里的初始速度.也许一个更好的解释是我想知道有多难以击中一个台球,以便它停在某一点上.

我一直在研究运动方程(http://en.wikipedia.org/wiki/Equations_of_motion),但无法弄清楚我的问题的正确方法是什么......

有任何想法吗?谢谢 - 我来自设计而不是科学背景.

更新:Fiirhok拥有固定加速度值的解决方案; HTML + jQuery演示:
http://pastebin.com/ekDwCYvj
有没有办法用小数值或缓动函数做到这一点?根据我的经验,这样做的好处是固定加速度和基于帧的动画有时会超过最终点并需要强制,从而产生轻微的捕捉故障.

drag motion easing-functions

5
推荐指数
1
解决办法
3582
查看次数

在C中重新分配结构

我是C的新手并尝试使用结构.在我创建了一个结构后,是否可以用大括号重新分配它?

typedef struct {
    int height;
    int age;
} Person;

int main (void)
{
    Person bill = {100,35};
    bill = {120,34}; // error: expected expression before ‘{’ token
    bill = Person {120,34}; // error: expected expression before ‘Person’

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c

3
推荐指数
1
解决办法
617
查看次数

标签 统计

javascript ×2

c ×1

colors ×1

currency ×1

drag ×1

easing-functions ×1

igoogle ×1

jquery ×1

motion ×1

python ×1

string ×1