Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript制作图像;“抖动”;或;颤抖;?_Javascript_Html_Image_Vibration - Fatal编程技术网

如何使用javascript制作图像;“抖动”;或;颤抖;?

如何使用javascript制作图像;“抖动”;或;颤抖;?,javascript,html,image,vibration,Javascript,Html,Image,Vibration,所以我的问题很简单,我正在用HTML构建一个网页,我想在其中加入一点JavaScript,使图像在相对狭小的空间/模式中“振动”或“抖动”基本上来回移动 我做了一些研究,发现: Copy the below code and paste it into the <HEAD> section of your page Example:<head>Code Here</head> <style> .jc{ position:relative; } &l

所以我的问题很简单,我正在用HTML构建一个网页,我想在其中加入一点JavaScript,使图像在相对狭小的空间/模式中“振动”或“抖动”基本上来回移动

我做了一些研究,发现:

Copy the below code and paste it into the <HEAD> section of your page
Example:<head>Code Here</head>
<style>
.jc{
position:relative;
}
</style>

<script language="JavaScript1.2">

var ns6=document.getElementById&&!document.all
var ie=document.all

var customcollect=new Array()
var i=0

function jiggleit(num){
if ((!document.all&&!document.getElementById)) return;
customcollect[num].style.left=(parseInt(customcollect[num].style.left)==-1)? customcollect[num].style.left=1 : customcollect[num].style.left=-1
}

function init(){
if (ie){
while (eval("document.all.jiggle"+i)!=null){
customcollect[i]= eval("document.all.jiggle"+i)
i++
} 
}
else if (ns6){
while (document.getElementById("jiggle"+i)!=null){
customcollect[i]= document.getElementById("jiggle"+i)
i++
}
}

if (customcollect.length==1)
setInterval("jiggleit(0)",80)
else if (customcollect.length>1)
for (y=0;y<customcollect.length;y++){
var tempvariable='setInterval("jiggleit('+y+')",'+'100 )'
eval(tempvariable)
}
}

window.onload=init

</script>

NOW PASTE THIS ANYWHERE YOU WISH YOUR IMAGE TO APPEAR

<span id="jiggle0" class="jc"><b>YOUR IMAGE URL HERE</b></span>
复制下面的代码并将其粘贴到页面的部分
示例:这里的代码
.jc{
位置:相对位置;
}
var ns6=document.getElementById&!文件。全部
var ie=document.all
var customcollect=新数组()
变量i=0
函数jiggleit(num){
if((!document.all&&!document.getElementById))返回;
customcollect[num].style.left=(parseInt(customcollect[num].style.left)=-1)?customcollect[num].style.left=1:customcollect[num].style.left=-1
}
函数init(){
如果(即){
while(eval(“document.all.jiggle”+i)!=null){
customcollect[i]=eval(“document.all.jiggle”+i)
我++
} 
}
否则,如果(ns6){
while(document.getElementById(“抖动”+i)!=null){
customcollect[i]=document.getElementById(“抖动”+i)
我++
}
}
if(customcollect.length==1)
设置间隔(“抖动(0)”,80)
else if(customcollect.length>1)

对于(y=0;y这是您想要的:


使用Mootools,Fx.Shake。签出!

此行有一个错误:

customcollect[num].style.left=(parseInt(customcollect[num].style.left)==-1)? customcollect[num].style.left=1 : customcollect[num].style.left=-1
您可能想要:

customcollect[num].style.left=(parseInt(customcollect[num].style.left)==-1) ? 1 : -1;

对不起,我不知道上面的代码有什么问题


我讨厌吹嘘自己的喇叭,但我最近发布了一个插件,如果你愿意使用jQuery,它可能适合你。它被称为。你可以自定义X范围、Y范围、旋转范围、隆隆声速度和事件类型。它可以用于任何元素,因此如果你愿意,你可以直接将它应用到图像或图像所在的div中<我们需要看到你实际使用的HTML,而不是指令。在jsFIDDel.NET上设置一个小提琴。此外,如果你做了很多动画相关的编码,你应该考虑其中的许多动画库。这样可以节省很多麻烦。