Here is a text slider and content of slider we can add through the given text box, when we add multi-lines through the text box then all lines one by one adding to different different slides and we can get it from Next
or previous
button. but when i add content to slider by textbox then the first time content not show directly, here i need to once click on next or previous button, then the slider content show. Right ?
But i want that the first slide of slider must show instantly when we add content through text box. Can i know what mistake am making plz make it solve.
Here is my All Code.
<button class="prev" onclick="plusSlides(-1)">Previous</button>
<button class="next" onclick="plusSlides(1)">Next</button>
<br>
<textarea class="input" id="input" placeholder="Message..."></textarea>
<button class="waves-effect waves-light" id="send-btn">Send</button>
<br> <br>
<div class="detailcontainer">
</div>
<style>
.detail-items {
display: none;
}
.detailcontainer {
background : yellow;
width: 200px;
}
</style>
<script>
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("detail-items");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
</script>
<script>
const sendButton = document.getElementById('send-btn');
const textArea = document.getElementById('input');
const innerDiv = document.getElementsByClassName('detailcontainer')[0];
var message = textArea.value;
sendButton.addEventListener('click', function() {
// split the textarea entries into an array
let lines = (textArea.value).split("
");
// iterate over each line, creating a div/span and inserting into the DOM
lines.forEach( (line) => {
let encodedLine = encodeHtmlEntity(line);
let newElement = `<div class="detail-items">${encodedLine}</div>`;
innerDiv.innerHTML += newElement;
});
// reset the textarea
textArea.value = '';
});
function encodeHtmlEntity(input) {
var output = input.replace(/[u00A0-u9999<>&]/gim, function(i) {
return '&#' + i.charCodeAt(0) + ';';
});
return output;
}
</script>
question from:
https://stackoverflow.com/questions/65952287/slider-content-not-showing-before-click-on-next-or-previous-button 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…