js如何实现连接图片显示但是又不能点击

JavaScript09

js如何实现连接图片显示但是又不能点击,第1张

给你一个参考,本人网站用的广告代码。

<script language=JavaScript>

var elady_step=3//1:small, 3:middle, 5:big

var elady_speed=50//20:fast, 50:middle, 80:slow

var e_tp=new Array()

var e_tplink=new Array()

var adNum_elady1=0

var elady_stop_sh=0

var elady_star_sh=1

function elady1_moveImg(){

if ((!document.all&&!document.getElementById)||(elady_stop_sh==0)) return

if (elady_star_sh==1){

document.all.elady1_divimg.style.pixelTop=parseInt(document.all.elady1_divimg.style.pixelTop)+elady_step}

else if (elady_star_sh==2){

document.all.elady1_divimg.style.pixelLeft=parseInt(document.all.elady1_divimg.style.pixelLeft)+elady_step}

else if (elady_star_sh==3){

document.all.elady1_divimg.style.pixelTop=parseInt(document.all.elady1_divimg.style.pixelTop)-elady_step}

else{

document.all.elady1_divimg.style.pixelLeft=parseInt(document.all.elady1_divimg.style.pixelLeft)-elady_step}

if (elady_star_sh<4) elady_star_sh++

else elady_star_sh=1

setTimeout("elady1_moveImg()",elady_speed)}

e_tplink[0]=""

e_tp[0]="img/500x250_1.jpg"

e_tplink[1]=""

e_tp[1]="img/500x250_2.jpg"

e_tplink[2]=""

e_tp[2]="img/500x250_3.jpg"

e_tplink[3]=""

e_tp[3]="img/500x250_4.jpg"

var currentimage=new Array()

for (i=0i<=3i++){currentimage[i]=new Image()

currentimage[i].src=e_tp[i]

}

function elady1_set(){ if (document.all)

{ e_tprotator.filters.revealTrans.Transition=Math.floor(Math.random()*23)

e_tprotator.filters.revealTrans.apply() }

}

function elady1_playCo()

{ if (document.all) e_tprotator.filters.revealTrans.play()

}function elady1_nextAd(){ if(adNum_elady1<e_tp.length-1)adNum_elady1++

else adNum_elady1=0

elady1_set()

document.images.e_tprotator.src=e_tp[adNum_elady1]

elady1_playCo()

theTimer=setTimeout("elady1_nextAd()", 4000)}

function elady1_linkurl(){ jumpUrl=e_tplink[adNum_elady1]

jumpTarget='_blank'

if (jumpUrl != ''){ if (jumpTarget != '')window.open(jumpUrl,jumpTarget)

else location.href=jumpUrl

}}

function elady1_listMsg()

{ status=e_tplink[adNum_elady1]

document.returnValue = true}

document.write("<div id='elady1_divimg' style='position:relative'>")

document.write('<img style="FILTER: revealTrans(duration=2,transition=20)" height=250 src="javascript:elady1_nextAd()" width=500 border=0 name=e_tprotator >')

document.write("</div>")

</script>

如果你要 “超级管理员才能点击,而其他的人不能点击”

那就不是JS了,ASP或PHP 加用户判读,如果是1,显示按键。如果不是,显示空白。

古老的做法是用settimeout或者setinterval实现循环动画,但是这样就会造成题主说的,在且页面的时候会造成混乱。

因为当页面失去焦点时浏览器不再渲染页面,但是settimeout/setinterval的请求不会停止,队列会一直堆积动画,当页面再次获得焦点时动画队列早已堆积了大量命令,就会导致动画混乱。

现在的做法,笼统地说,是使用requestanimationframe函数,用法和settimeout/setinterval类似,只不过requestanimationframe不接受时间参数,函数的执行频率由浏览器的渲染帧数决定,这就实现了由浏览器决定动画队列,避免了动画混乱。当然也可以使用一些现成的轮播图插件,题主可以自己百度,这里对比举例说明一下settimeout和requestanimationframe的用法。

//用setTimeout实现在控制台循环输出hello world

function fun(){

    console.log('hello world')

    setTimeout(function(){

        fun()

    },3000)

}

fun()//执行fun函数,就可以每隔3000毫秒递归的输出hello world

//用reqestanimationframe实现在控制台循环输出hello world

function fun(){

    console.log('hello world')

    requestAnimationFrame(function(){

        fun()

    })

}

fun()//执行fun函数,就可以每隔3000毫秒递归的输出hello world

//requestAnimationFrame没有时间参数,所以直接使用不能控制间隔

//但我们可以人为的限制执行间隔,方法如下

function fun(last_time){

        if(new Date().getTime() - last_time > 3000){

            console.log('hello world')

            requestAnimationFrame(function(){

                fun(new Date().getTime())

            })

        }else{

            requestAnimationFrame(function(){

                fun(last_time)

            })

        }

}

fun(new Date().getTime())

//这样就可以为requestAnimationFrame设置间隔,实现每隔3000毫秒输出hello world

//抱歉我主写c副写python偶尔写javaweb,分号用的有些乱。