用js怎样让一张图片隔一段时间变成另一张?
3个回答
展开全部
<body>
<img id="p" />
<script>
var t = new Array("你的图片1", "你的图片2", "你的图片3");
var i = 0;
function changepic() {
if (i > 2) i = 0;
var p = document.getElementById("p");
p.src = t[i];i++;setTimeout(changepic, 4000);
}
window.onload = changepic;
</script>
</body>
<img id="p" />
<script>
var t = new Array("你的图片1", "你的图片2", "你的图片3");
var i = 0;
function changepic() {
if (i > 2) i = 0;
var p = document.getElementById("p");
p.src = t[i];i++;setTimeout(changepic, 4000);
}
window.onload = changepic;
</script>
</body>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用JavaScript实现图片轮换效果代码
<div id="oTransContainer" style="filter: progid:DXImageTransform.Microsoft.Wipe(GradientSize=1.0,wipeStyle=0, motion='forward'); width:475px;height:260px;float:left;margin:11px 0 0 0;">
<div style="width:386px; height:219px;">
<img alt="" class="pic" id="oDIV1" src="images/1.jpg" width="386" height="219"/>
<script language="javascript" type="text/javascript">
var NowFrame = 1;var MaxFrame = 8;var bStart = 0;function fnToggle(){var next = NowFrame + 1;if(next == MaxFrame+1) {NowFrame = MaxFrame;next = 1;}if(bStart == 0){bStart = 1;setTimeout('fnToggle()', 2000);return;}else{oTransContainer.filters[0].Apply();document.images['oDIV'+next].style.display = "";document.images['oDIV'+NowFrame].style.display = "none";oTransContainer.filters[0].Play(duration=2);if(NowFrame == MaxFrame){NowFrame = 1;}else{NowFrame++;}} setTimeout('fnToggle()', 6000);}fnToggle();
</script>
<img alt="" class="pic" id="oDIV2" src="images/2.jpg" width="386" height="219" style="DISPLAY: none;"/>
<img alt="" class="pic" id="oDIV3" src="images/3.jpg" width="386" height="219" style="DISPLAY: none;"/>
<img alt="" class="pic" id="oDIV4" src="images/4.jpg" width="386" height="219" style="DISPLAY: none;"/>
<img alt="" class="pic" id="oDIV5" src="images/5.jpg" width="386" height="219" style="DISPLAY: none;"/>
<img alt="" class="pic" id="oDIV6" src="images/6.jpg" width="386" height="219" style="DISPLAY: none;"/>
<img alt="" class="pic" id="oDIV7" src="images/7.jpg" width="386" height="219" style="DISPLAY: none;"/>
<img alt="" class="pic" id="oDIV8" src="images/8.jpg" width="386" height="219" style="DISPLAY: none;"/>
</div>
</div>
<div id="oTransContainer" style="filter: progid:DXImageTransform.Microsoft.Wipe(GradientSize=1.0,wipeStyle=0, motion='forward'); width:475px;height:260px;float:left;margin:11px 0 0 0;">
<div style="width:386px; height:219px;">
<img alt="" class="pic" id="oDIV1" src="images/1.jpg" width="386" height="219"/>
<script language="javascript" type="text/javascript">
var NowFrame = 1;var MaxFrame = 8;var bStart = 0;function fnToggle(){var next = NowFrame + 1;if(next == MaxFrame+1) {NowFrame = MaxFrame;next = 1;}if(bStart == 0){bStart = 1;setTimeout('fnToggle()', 2000);return;}else{oTransContainer.filters[0].Apply();document.images['oDIV'+next].style.display = "";document.images['oDIV'+NowFrame].style.display = "none";oTransContainer.filters[0].Play(duration=2);if(NowFrame == MaxFrame){NowFrame = 1;}else{NowFrame++;}} setTimeout('fnToggle()', 6000);}fnToggle();
</script>
<img alt="" class="pic" id="oDIV2" src="images/2.jpg" width="386" height="219" style="DISPLAY: none;"/>
<img alt="" class="pic" id="oDIV3" src="images/3.jpg" width="386" height="219" style="DISPLAY: none;"/>
<img alt="" class="pic" id="oDIV4" src="images/4.jpg" width="386" height="219" style="DISPLAY: none;"/>
<img alt="" class="pic" id="oDIV5" src="images/5.jpg" width="386" height="219" style="DISPLAY: none;"/>
<img alt="" class="pic" id="oDIV6" src="images/6.jpg" width="386" height="219" style="DISPLAY: none;"/>
<img alt="" class="pic" id="oDIV7" src="images/7.jpg" width="386" height="219" style="DISPLAY: none;"/>
<img alt="" class="pic" id="oDIV8" src="images/8.jpg" width="386" height="219" style="DISPLAY: none;"/>
</div>
</div>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你可以找一些JQUERY的插件来完成这个效果。
个人推荐jQuery Cycle Plugin
http://malsup.com/jquery/cycle/adv.html
这个是演示效果,还有更多的效果,你可以自己在里面点点看看。
有问题加我Q:282975285。
个人推荐jQuery Cycle Plugin
http://malsup.com/jquery/cycle/adv.html
这个是演示效果,还有更多的效果,你可以自己在里面点点看看。
有问题加我Q:282975285。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询