- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 javascript 和 css(没有 jquery 或其他任何东西)中的幻灯片作业有问题。
此幻灯片应该有两种模式,一种是 i) 自动显示图片,另一种是 ii) 手动更改它们。该按钮应分别更改。两种模式都可以正常工作,但我的切换按钮不...
感谢任何帮助!
这是我的代码:
CSS
<style type="text/css">
body { padding-top: 2%; }
div {border:solid red 1px; width:550px; padding:10px ; text-align:center;}
textarea {background-color: #ccc;}
.Slides {display : none; }
</style>
HTML
<form id="form1" name="form1" method = "GET" action="">
<input type = "text" id="current" name="s" value="" />
<input type = "button" value="PREVIOUS" onclick="myClick_previous()" />
<input type = "button" value="NEXT" onclick="myClick()" />
<!-- <input type = "button" value="STEP" id="step" onclick="ToggleButton" /> -->
<button class="controls" id="pause">Pause</button>
</form>
<div id="container" >
simple SLIDE SHOW
<img id="Slide001" class="Slides" src="slides/Slide001.jpg" />
<img id="Slide002" class="Slides" src="slides/Slide002.jpg" />
<img id="Slide003" class="Slides" src="slides/Slide003.jpg" />
<img id="Slide004" class="Slides" src="slides/Slide004.jpg" />
<img id="Slide005" class="Slides" src="slides/Slide005.jpg" />
<img id="Slide006" class="Slides" src="slides/Slide006.jpg" />
<textarea id="TimeLineInfos" name="TimeLineInfos" rows="4" cols="50" ></textarea>
</div>
Javascript
<script>
var currentSlide = 1;
document.getElementById('Slide001').style.display = "inline" ;
document.getElementById('current').value = 'Slide00' + (currentSlide +0);
document.getElementById('TimeLineInfos').value = 'Slide00'+currentSlide + ' : ' + TimeEst() + '\n';
function myClick(){
var t = TimeEst()
currentSlide += 1 ;
if ( currentSlide != 7 ) {
var currentID = 'Slide00'+currentSlide ;
var previousID = 'Slide00'+(currentSlide - 1) ;
}
if ( currentSlide == 7 ) {
currentSlide = 1
var currentID = 'Slide001'
var previousID = 'Slide006'
}
document.getElementById(previousID).style.display = "none" ;
document.getElementById(currentID).style.display = "inline" ;
document.getElementById('current').value = currentID;
document.getElementById('TimeLineInfos').value += currentID + ' : ' + t + '\n';
//sendTimeLine(currentID,t);
//document.form1.submit();
}
function myClick_previous(){
var t = TimeEst()
currentSlide -= 1 ;
if ( currentSlide != 0 ) {
var currentID = 'Slide00'+currentSlide ;
var previousID = 'Slide00'+(currentSlide + 1) ;
}
if ( currentSlide == 0 ) {
currentSlide = 6
var currentID = 'Slide006'
var previousID = 'Slide001'
}
document.getElementById(previousID).style.display = "none" ;
document.getElementById(currentID).style.display = "inline" ;
document.getElementById('current').value = currentID;
document.getElementById('TimeLineInfos').value += currentID + ' : ' + t + '\n';
}
var myIndex = 0;
slide();
var timer;
function slide() {
var i;
var x = document.getElementsByClassName("Slides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
myIndex++;
if (myIndex > x.length) {myIndex = 1}
x[myIndex-1].style.display = "block";
timer=setTimeout(slide, 3000); // Change image every 3seconds
}
//from down here is my problematic code
var playing = true;
var pauseButton = document.getElementById('pause');
function pauseSlideshow(){
pauseButton.innerHTML = 'Play';
playing = false;
clearInterval(timer);
}
function playSlideshow(){
pauseButton.innerHTML = 'Pause';
playing = true;
slideInterval = setInterval(slide,3000);
}
pauseButton.onclick = function(){
if(playing){ pauseSlideshow(); }
else{ slide(); }
};
function TimeEst(){
var d = new Date();
var t = d.getTime() ;// + "." + d.getMilliseconds();
return t;
}
</script>
最佳答案
我终于找到了...答案比我想象的要简单!(我只是张贴它以防有人需要它作为示例...)
HTML,CSS保持不变,只是Javascript变了!
开始吧:
<script>
var currentSlide = 1;
var flag=1;
document.getElementById('Slide001').style.display = "inline" ;
document.getElementById('current').value = 'Slide00' + (currentSlide +0);
document.getElementById('TimeLineInfos').value = 'Slide00'+currentSlide + ' : ' + TimeEst() + '\n';
var timer = setInterval(function(){ myClick_next(); }, 3000);
var playing=true;
function toggle()
{
if(playing==true)
{
playing=false;
clearInterval(timer);
document.getElementById("STEP").value = "AUTO";
}
else
{
playing=true;
timer=setInterval(function(){ myClick_next(); }, 3000);
document.getElementById("STEP").value = "STEP";
}
}
document.getElementById("BACK").disabled = true;
function myClick_next(){
var t = TimeEst()
currentSlide += 1 ;
document.getElementById("BACK").disabled = false;
if ( currentSlide != 7 ) {
var currentID = 'Slide00'+currentSlide ;
var previousID = 'Slide00'+(currentSlide - 1) ;
}
if ( currentSlide == 7 ) {
currentSlide = 1
var currentID = 'Slide001'
var previousID = 'Slide006'
}
document.getElementById(previousID).style.display = "none" ;
document.getElementById(currentID).style.display = "inline" ;
document.getElementById('current').value = currentID;
document.getElementById('TimeLineInfos').value += currentID + ' : ' + t + '\n';
//sendTimeLine(currentID,t);
//document.form1.submit();
}
function myClick_previous(){
var t = TimeEst()
currentSlide -= 1 ;
if ( currentSlide != 0 ) {
var currentID = 'Slide00'+currentSlide ;
var previousID = 'Slide00'+(currentSlide + 1) ;
}
if ( currentSlide == 1 ) {
document.getElementById("BACK").disabled = true;
//currentSlide = 6
//var currentID = 'Slide006'
//var previousID = 'Slide001'
}
document.getElementById(previousID).style.display = "none" ;
document.getElementById(currentID).style.display = "inline" ;
document.getElementById('current').value = currentID;
document.getElementById('TimeLineInfos').value += currentID + ' : ' + t + '\n';
//sendTimeLine(currentID,t);
//document.form1.submit();
}
function TimeEst(){
var d = new Date();
var t = d.getTime() ;// + "." + d.getMilliseconds();
return t;
}
</script>
关于javascript - 带切换按钮的幻灯片(自动/步进),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43022712/
有没有办法在 D 范围内创建一个步骤?例如,在 python 中, 范围(1、10、2)给我 [1, 3, 5, 7, 9] 1 .. 10 以内的所有赔率 有没有办法在 D 中使用
我在 javascript 和 css(没有 jquery 或其他任何东西)中的幻灯片作业有问题。 此幻灯片应该有两种模式,一种是 i) 自动显示图片,另一种是 ii) 手动更改它们。该按钮应分别更改
我有一个在堆栈上声明的结构。这是结构的样子: struct MyStruct { int integer; std::vector booleanVector; }; 当我使用 gdb
我的容器进入第一行,但是当 float 导致第二行开始时,第二行没有进入。如何防止踩踏? HTML echo "". $row["FirstName"]. "" . $day_month .""; C
我们在 VMWare 中运行 Linux Debian。使用 gdb 调试时,如果尝试跨过 memset/memcmp/strcmp 等...,gdb 会返回以下错误: Cannot find bou
我是一名优秀的程序员,十分优秀!