基于所选滑块图像的自定义页面html

如何解决基于所选滑块图像的自定义页面html

很抱歉,如果我在这里错误地使用了一些术语,或者不知道正确描述这些术语的术语,但是...

简单的部分-我想创建一个“车轮”样式滑块,显示三张图片,主要的“选定”图片位于最前面,另外两张图片按比例缩小,在它们后面,但可以快速轻松地单击和查看。

硬部分-我希望将任何图片设置在滑轮的最前面的主要部分中,以显示有关该特定切换图片和该图片的信息(页面宽度)。然后,当您切换到其他幻灯片/图片时,只有关于该幻灯片/图片的信息会被放置在滑块/拨轮下方。

我想我的出发点是为切换/滑动图片轮获取一些代码。然后以某种方式为突出显示的图片创建某种事件触发类型编码,并将其与某种html隐藏/显示编码结合起来。

我附上了一些不良的草图,以帮助我形象地描绘出我在说什么。

任何见解都是值得欢迎的,即使它是一些关键字可以帮助我缩小Google搜索范围并找到一些资源。 Slide & Page Layout Sketch

谢谢

解决方法

听起来像您需要一些CSS和JS才能使这项工作完成。

首先,您将需要HTML布局。我有整个旋转木马(.container)的包装纸。我有左右箭头以及用于图像的第二个包装器。

对于转盘下方的文本,我有第二个元素(.content),其中包含三个元素,每个元素与图像相关。仅在将.shown应用于元素时显示文本。

<div class="container">

  <div class="left">&lt;</div>
  
  <div>
    <div class="img img-left"></div>
    <div class="img img-center"></div>
    <div class="img img-right"></div>
  </div>

  <div class="right">&gt;</div>
  
</div>

<div class="content">
  <div class="text">
    Amazing Sunset
  </div>
  <div class="text shown">
    Fall Leaves
  </div>
  <div class="text">
    Misty Sunlight
  </div>
</div>

对于CSS,我选择制作.container position: relative,以便可以在孩子上使用position: absolute。我有3个图像班。 img-leftimg-rightimg-center。这些可以动画。箭头只是垂直居中

.container {
  position: relative;

  height: 85vh;
}

.img {
  position: absolute;
  z-index: 2;

  height: 75vh;
  width: 121vh;

  max-height: 300px;
  max-width: 511px;

  top: 0; bottom: 0;
  left: 0; right: 0;
  margin: auto;

  transition: transform 0.3s,z-index 0s linear 0.15s;
}

.img:nth-of-type(1) {
  background: url('https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg') center/contain no-repeat;
}

.img:nth-of-type(2) {
  background: url('https://cdn.pixabay.com/photo/2015/12/01/20/28/road-1072823__340.jpg') center/contain no-repeat;
}

.img:nth-of-type(3) {
  background: url('https://cdn.pixabay.com/photo/2015/09/09/16/05/forest-931706__340.jpg') center/contain no-repeat;
}

.img-center {
  z-index: 5;
}

.img-right {
  transform: translateX(200px) scale(0.7);
}

.img-left {
  transform: translateX(-200px) scale(0.7);
}

.left,.right {
  position: absolute;
  z-index: 7;

  top: 50%;

  font-size: 48px;
  font-family: monospace;

  transform: translateY(-50%);
  user-select: none;
}

.left {
  left: 32px;
}

.right {
  right: 32px;
}

.content {
  height: 15vh;
}

.text {
  display: none;

  text-align: center;
  font-size: 32px;
}

.text.shown {
  display: block;
}

JavaScript使事情变得越来越有趣。我创建了一个名为nextImage()的函数,该函数接受一个表示切换方向的布尔值。首先,它获取当前居中的图像,然后基于该图像获取下一个和上一个元素同级。如果居中的图像恰好是第一个或最后一个元素,则nextpre将是undefined。接下来处理。完成此操作后,将根据方向重新分配CSS类。

function nextImage(forward) {
  let currentCentered = document.querySelector('.img-center'),next = currentCentered.nextElementSibling,pre = currentCentered.previousElementSibling;
  
  //pre and next may not be elements if currentCentered is the frist or last element.
  if (!next) { //Centered Element is the frist
    next = pre.previousElementSibling;
  } else if (!pre) { //Centered Element is the last
     pre = next.nextElementSibling;
  }
  
  if (forward) {    
    //Move the previously centered image to the right
    currentCentered.classList.remove('img-center');
    currentCentered.classList.add('img-right');

    //Move the previously left image to the center
    pre.classList.remove('img-left');
    pre.classList.add('img-center');

    //Move the previously right image to the left
    next.classList.remove('img-right');
    next.classList.add('img-left');
    
  } else {
  
    //Move the previously centered image to the left
    currentCentered.classList.remove('img-center');
    currentCentered.classList.add('img-left');

    //Move the previously left image to the right
    pre.classList.remove('img-left');
    pre.classList.add('img-right');

    //Move the previously right image to the center
    next.classList.remove('img-right');
    next.classList.add('img-center');
  }
  
  //Update the text
  let currentText = document.querySelector('.text.shown'),newText;
  
  if (forward) {
    //Get the previous element;
    newText = currentText.previousElementSibling;
    
    //If it doesn't exist get the last element
    if (!newText) {
      newText = currentText.nextElementSibling.nextElementSibling;
    }
  } else {
    //Get the next element;
    newText = currentText.nextElementSibling;
    
    //If it doesn't exist get the frist element
    if (!newText) {
      newText = currentText.previousElementSibling.previousElementSibling;
    }
  }
  
  //Apply class change
  currentText.classList.remove('shown');
  newText.classList.add('shown');
}

现在将onclick="nextImage(false)"添加到左箭头,并将onclick="nextImage(true)"添加到右箭头,即可进行导航。

自从您说您希望图片如此可点击以来,我添加了第二个功能,可让您滚动到给定的图像。它获取下一个和上一个元素,并确保它们是实际元素。然后它基于nextImage()next是居中图像来调用pre函数。

function switchImage(imgEle) {
  let next = imgEle.nextElementSibling,pre = imgEle.previousElementSibling;
    
  //Make sure they are actually elements  
  if (!next) {
    next = pre.previousElementSibling;
  }
  
  if (!pre) {
    pre = next.nextElementSibling;
  }
  
  if (next.classList.contains('img-center')) {
    nextImage(true);
  } else if (pre.classList.contains('img-center')) {
    nextImage(false);
  }
}

您现在要做的就是将onclick="switchImage(this)"添加到每个图像元素中。

将所有内容加在一起,您应该在下面获得类似此代码段的内容

function nextImage(forward) {
  let currentCentered = document.querySelector('.img-center'),newText;
  
  if (forward) {
    //Get the previous element;
    newText = currentText.previousElementSibling;
    
    //If it doesn't exist get the last element
    if (!newText) {
      newText = currentText.nextElementSibling.nextElementSibling;
    }
  } else {
    //Get the next element;
    newText = currentText.nextElementSibling;
    
    //If it doesn't exist get the frist element
    if (!newText) {
      newText = currentText.previousElementSibling.previousElementSibling;
    }
  }
  
  //Apply class change
  currentText.classList.remove('shown');
  newText.classList.add('shown');
}

function switchImage(imgEle) {
  let next = imgEle.nextElementSibling,pre = imgEle.previousElementSibling;
    
  //Make sure they are actually elements  
  if (!next) {
    next = pre.previousElementSibling;
  }
  
  if (!pre) {
    pre = next.nextElementSibling;
  }
  
  if (next.classList.contains('img-center')) {
    nextImage(true);
  } else if (pre.classList.contains('img-center')) {
    nextImage(false);
  }
}
.container {
  position: relative;
  
  height: 85vh;
}

.img {
  position: absolute;
  z-index: 2;

  height: 75vh;
  width: 121vh;

  max-height: 300px;
  max-width: 511px;

  top: 0; bottom: 0;
  left: 0; right: 0;
  margin: auto;
  
  transition: transform 0.3s,.right {
  position: absolute;
  z-index: 7;
  
  top: 50%;

  font-size: 48px;
  font-family: monospace;
  
  transform: translateY(-50%);
  user-select: none;
}

.left {
  left: 32px;
}

.right {
  right: 32px;
}

.content {
  height: 15vh;
}

.text {
  display: none;

  text-align: center;
  font-size: 32px;
}

.text.shown {
  display: block;
}
<div class="container">

  <div class="left" onclick="nextImage(false)">&lt;</div>
  
  <div>
    <div class="img img-left" onclick="switchImage(this)"></div>
    <div class="img img-center" onclick="switchImage(this)"></div>
    <div class="img img-right" onclick="switchImage(this)"></div>
  </div>

  <div class="right" onclick="nextImage(true)">&gt;</div>
  
</div>

<div class="content">
  <div class="text">
    Amazing Sunset
  </div>
  <div class="text shown">
    Fall Leaves
  </div>
  <div class="text">
    Misty Sunlight
  </div>
</div>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-