旧的javascript幻灯片只显示wihtout幻灯片(onclick)
Old javascript slide show wihtout slide just (onclick)
你好,我需要用一个类似幻灯片的按钮来切换图像,但不需要滑动,我已经尝试了一些东西,希望有人能帮我处理这种代码。我在做这个
<img id="imageswitch" src="image/1.jpg" width="400" height="286" alt="photo1" />
<script>
var image = document.getElementById("imageswitch")
function switchImage(){
if(image.src = "image/1.jpg"){
image.src = "image/2.jpg";
}else if(image.src = "image/2.jpg"){
image.src = "image/3.jpg";
console.log("marche")
}else{
console.log("dont work man")
}
}
document.getElementById("boutonright").addEventListener("click", function () {
switchImage();
});
- 将图像路径放入阵列中
- 点击按钮操作您的数组:
var image = document.getElementById("imageswitch"),
images = [
"http://placehold.it/400x286/fb0/?text=1",
"http://placehold.it/400x286/0bf/?text=2",
"http://placehold.it/400x286/bf0/?text=3"
];
function switchImage(){
images.push( images.shift() );
image.src = images[0];
}
document.getElementById("boutonright").addEventListener("click", switchImage);
#imageswitch{height:180px;}
<button id="boutonright">NEXT</button><br>
<img id="imageswitch" src="http://placehold.it/400x286/fb0/?text=1" alt="photo1" />
如果您想要同时拥有PREV
和NEXT
按钮:
var image = document.getElementById("imageswitch"),
images = [
"http://placehold.it/400x286/fb0/?text=1",
"http://placehold.it/400x286/0bf/?text=2",
"http://placehold.it/400x286/bf0/?text=3"
];
function switchImage(){
if(this.id==="next") images.push( images.shift() );
else /* id==="prev*/ images.unshift( images.pop() );
image.src = images[0];
}
document.getElementById("prev").addEventListener("click", switchImage);
document.getElementById("next").addEventListener("click", switchImage);
#imageswitch{height:180px;}
<button id="prev">PREV</button><button id="next">NEXT</button><br>
<img id="imageswitch" src="http://placehold.it/400x286/fb0/?text=1" alt="photo1" />
相关文章:
- 幻灯片滚动javascript不起作用
- 让文本输入幻灯片显示输入时的新文本输入?然后向后滑动
- 如何在执行此特定onclick事件时执行JavaScript函数
- Setting default onclick behavior for <img> tag in gene
- Javascript全局onclick监听器
- 创建具有可变长度幻灯片显示的幻灯片
- 如何调用“;链接_;在onclick事件上使用Javascript
- onclick函数需要双击,因为类分配延迟
- 如何使用jquery迭代具有相同属性的html元素并查找onclick事件
- 使用onclick绘制SVG路径
- 如何将数据从onclick按钮传递到变量
- 选择onclick事件jquery
- I'我设计了一个下拉菜单,onclick会出现,而on blur会消失
- 如何刷新列表框内容onclick或blur事件
- OnClick/Onhover Javascript/jquery
- 通过幻灯片更改事件停止使用jquery的音频
- 执行php函数的onclick事件的其他替代方案
- 旧的javascript幻灯片只显示wihtout幻灯片(onclick)
- 停止和启动带有 onclick 事件的幻灯片放映
- JS onclick未执行幻灯片放映