我正在寻找一个简单的函数来将数组元素移动到数组中的新位置并重新排序索引,以便序列中没有间隙.它不需要使用关联数组.有人有这个想法吗?
$a = array(
0 => 'a',
1 => 'c',
2 => 'd',
3 => 'b',
4 => 'e',
);
print_r(moveElement(3,1))
//should output
[ 0 => 'a',
1 => 'b',
2 => 'c',
3 => 'd',
4 => 'e' ]
Run Code Online (Sandbox Code Playgroud) 有没有人有如何提高CSS3动画平滑度的秘籍或技巧?我正在使用css过渡将整个页面向左滑动,这比我想要的更加juttery.它是一个单独的元素,但它包含许多圆角,渐变,阴影等,因为它是一个复杂的页面.
在flash actionscript中,有一个方便的属性cacheAsBitmap,可以在动画开始之前将动画元素转换为位图.这是一个天赐之物,可以显着加快某些类型的动画.CSS有这样的东西吗?有没有其他提示可以在不简化页面设计的情况下提高性能?我正在考虑启用硬件加速或将动画标记为浏览器的高优先级.
如果不使用PHP 5.3的date_diff功能(我使用PHP 5.2.17),有一个简单而准确的方法来做到这一点?我正在考虑类似下面的代码,但我不知道如何解释闰年:
$days = ceil(abs( strtotime('2000-01-25') - strtotime('2010-02-20') ) / 86400);
$months = ???;
Run Code Online (Sandbox Code Playgroud)
我想弄清楚一个人的月龄.
我想要仅使用CSS来定位具有可见滚动条的元素.这可能没有JavaScript吗?
例如,如果我有3个div设置样式overflow-y:auto,如何仅在滚动条出现时更改它们的样式?
我试图获取文件的目录位置,我不知道如何得到它.我似乎找不到允许我这样做的模块.
所以例如说我有这个字符串:
/this/is/a/path/to/a/file.html
Run Code Online (Sandbox Code Playgroud)
我怎么能得到这个:
/this/is/a/path/to/a
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用这样的东西:
path.substr(0, path.lastIndexOf("/") - 1);
Run Code Online (Sandbox Code Playgroud)
但我不确定这是否与可能内置于节点的方法一样好.
我也尝试过:
var info = url.parse(full_path);
console.log(info);
Run Code Online (Sandbox Code Playgroud)
并且结果不会返回我要查找的内容,它会获得包含文件名的完整路径.
那么,节点中是否有内置功能可以做到这一点并做得好呢?
嗨,我一直在使用contentEditable一段时间了,我觉得我对它有很好的处理.回避我的一件事是如何获得部分或完全在用户选择范围内的所有节点的引用数组.有人有个主意吗?
这是从一开始:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function getSelectedNodes(){
var sel = window.getSelection();
try{var frag=sel.getRangeAt(0).cloneContents()}catch(e){return(false);}
var tempspan = document.createElement("span");
tempspan.appendChild(frag);
var selnodes = Array() //<<- how do I fill this array??
var output = ''
for(i in selnodes){
output += "A "+selnodes[i].tagName+" was found\n"
//do something cool with each element here...
}
return(output)
}
</script>
</head>
<body contentEditable="true" onkeypress="return(keypress(event))">
<div>This <strong>div</strong> is <em>content</em> <span class='red'>editable</span> and has …Run Code Online (Sandbox Code Playgroud) 是否可以在CSS变量中添加类名,或者是否可以通过其他方法进行设置,这样我就不必直接通过javascript操作每个变量了?我想将所有样式保留在CSS中,并仅使用JS打开相关的类。例如,如果在CSS中可能出现类似情况:
:root.white{ --bgcol:#FFF; --col:#000; }
:root.black{ --bgcol:#000; --col:#FFF; }
Run Code Online (Sandbox Code Playgroud)
然后,我可以直接从javascript 切换.blackor或.whiteclass来触发所有var进行更改。这种设置的最佳方法是什么?
考虑以下Javascript:
function getType(obj){
return(typeof(obj))
}
alert(typeof(obj)) //alerts "undefined" correctly
alert(getType(obj)) //throws an error: ReferenceError: obj is not defined
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况?有没有解决方法?我正在尝试编写一个函数来检查变量是否存在.
这是一个复杂的!我在Chrome中使用contentEditable,我遇到了头部融化问题.当我按下返回键时,Chrome会在innerHTML中插入一个新的div.这很好,很花哨.问题是在div的textContent中找不到换行符.我真的需要找到一种方法来将换行符添加到textContent中,与innerHTML中的div break相同.
有任何想法吗?
更新:
我可以使用innerText,但是当忽略页面加载时会出现换行符.我需要在这些方法中保持一致性.换句话说,我需要textContent来显示新输入的换行符或innerText来显示页面加载时存在的换行符.
这是一个更新的演示:
function checkit() {
var c1 = document.getElementById('c1')
alert("TEXTCONTENT:\n" + c1.textContent + "\n\nINNERTEXT:\n" + c1.innerText + "\n\nINNERHTML:\n" + c1.innerHTML)
}Run Code Online (Sandbox Code Playgroud)
div {padding: 20px; border-bottom: 1px solid #CCC;}Run Code Online (Sandbox Code Playgroud)
<div><a href="#" onclick="checkit()">check it</a></div>
<div contentEditable="true" id="c1">click inside this <b>div</b>,
press return and then press <b>check it</b> above</div>Run Code Online (Sandbox Code Playgroud)
这应该是一个简单的几何形状:如何计算在下面的代码中绘制线条的点,以便它形成2D锥形或楔形?
import flash.geom.Point;
//draw circle
var mc=new Sprite()
mc.graphics.lineStyle(0,0)
mc.graphics.drawCircle(0,0,30)
mc.x=mc.y=Math.random()*300+100
addChild(mc)
//draw lines:
graphics.lineStyle(0,0)
var p=new Point(Math.random()*500,Math.random()*400)
graphics.moveTo(p.x, p.y)
graphics.lineTo(mc.x,mc.y) // << should be point on edge of circle
graphics.moveTo(p.x, p.y)
graphics.lineTo(mc.x,mc.y) // << should be point on opposite edge of circle
Run Code Online (Sandbox Code Playgroud)
更新:
谢谢大家,我应该提到我的目标不是绘制楔形,而是从随机点到现有圆的边缘画一条线.
如果你对代数比动作更舒服,也许你可以看看这个图形并为我发布一个公式?
