简体   繁体   English

无法通过W3schools.com的移动浏览器自动幻灯片显示更改图像大小

[英]Unable to change image size from W3schools.com's automatic slideshow for mobile browser

To Whom it May Concern: 敬启者:

I used code from W3schools.com's tutorial on creating an automatic image slideshow. 我使用了W3schools.com教程中的代码来创建自动图像幻灯片。 The slideshow works great on desktop dimensions, however, when changing to mobile screen dimensions, I am unable to shrink the slideshow dimensions accordingly. 幻灯片在桌面尺寸上效果很好,但是,当更改为移动屏幕尺寸时,我无法相应地缩小幻灯片尺寸。

I am able to do so with all other images, as I am competent with HTML/CSS, but this has me stumped. 我能够处理所有其他图像,因为我能胜任HTML / CSS,但这让我很困惑。 Not sure if it's the 'link rel' relating to W3schools, the javascript, or something else I am missing. 不知道这是否是与W3schools,JavaScript或其他我所缺少的“链接相关”。 Thanks for any and all help. 感谢您提供的所有帮助。 The code is as follows: 代码如下:

HTML: HTML:

<div class="w3-content w3-section">
<img class="mySlides" src="slider_3.png">
<img class="mySlides" src="slider_2.png">
<img class="mySlides" src="slider_1.png">
<img class="mySlides" src="slider_4.png">
<img class="mySlides" src="slider_5.png">

CSS: CSS:

.mySlides {
  display: none;
  width: 960px;
  height: 350px;
}

/* For mobile phones: */
@media screen and (min-width: 300px) and (max-width: 900px) {

.mySlides {
  display: none;
  width: 100%;
  height: auto;
}

and the Java: 和Java:

    var myIndex = 0;
carousel();

function carousel() {
  var i;
  var x = document.getElementsByClassName("mySlides");
  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";
  setTimeout(carousel, 7000); // Change image every 7 seconds
}

A christmas miracle happened. 圣诞节奇迹发生了。 Now it is working! 现在可以了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM