无法插入地图像旋转木马

0

的问题

我的工作与这个图像旋转木马,我有这个代码,但有一个问题,在这样的代码,我想插入9个不同的 或者 当地的图像/图片的url的 ,而不是这种逻辑 https://picsum.photos/id/'+(i+32)+'/600/400/backgroundImage:(i)=> 但同时替换上 https:// 链接与 地的图像/图象网址的 存在仅仅一个类似的图像,已经显示出来,我不知道我怎么可以添加不同的图像,不是重复在旋转木马

如图像,我要插入

图1- https://cdn.pixabay.com/photo/2017/01/08/13/58/cube-1963036__340.jpg

图2- https://hatrabbits.com/wp-content/uploads/2017/01/random.jpg

图3- https://cdn.pixabay.com/photo/2015/03/17/02/01/cubes-677092__480.png

图4- https://www.destructoid.com/wp-content/uploads/2021/09/Lost-in-Random-Shadowman-screenshot.jpg

图5- https://static1.srcdn.com/wordpress/wp-content/uploads/2021/03/Among-Us-Random-Name-Generator.jpg

象6- https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTTL71W2u3jfYvvp2MXCfvVwHoyM-cioxCZkA&usqp=CAU

像7- https://files.realpython.com/media/random_data_watermark.576078a4008d.jpg

像个8 https://uploads-ssl.webflow.com/5a9ee6416e90d20001b20038/5f248ec98e860a09db602367_random-object-generator%20(1).png

图9- https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRB9VVgVQhCfCnD7udlz3tJnAR61x76JZ3Ftw&usqp=CAU

    <!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>scrolling</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<link rel="stylesheet" href="./style.css">

</head>
<style type="text/css">
  html, body, .stage, .ring, .img {
  width:100%;
  height: 100%;
  transform-style: preserve-3d;
  user-select:none;
}

html, body, .stage {
  overflow:hidden;
  background:#000;
  
}

div, svg {
  position: absolute;
}

.container {
  perspective: 2000px;
  width: 1000px;
  height: 500px;  
  left:50%;
  top:50%;
  transform:translate(-50%,-50%);
}
</style>
<body>
<!-- partial:index.partial.html -->
<div class="stage">
  
  
<div class="container">
  <div class="ring">
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
  </div>
</div>

</div>
<!-- partial -->
  <script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/3.6.1/gsap.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js'></script>
<script>
  let xPos = 0;

gsap.timeline()
    .set('.ring', { rotationY:180, cursor:'grab' }) //set initial rotationY so the parallax jump happens off screen
    .set('.img',  { // apply transform rotations to each image
      rotateY: (i)=> i*-36,
      transformOrigin: '50% 50% 1600px',
      z: -1600,
      backgroundImage:(i)=>'url(https://picsum.photos/id/'+(i+32)+'/600/400/)',
      backgroundPosition:(i)=>getBgPos(i),
      backfaceVisibility:'hidden'
    })    
    .from('.img', {
      duration:1.5,
      y:200,
      opacity:0,
      stagger:0.1,
      ease:'expo'
    })
    .add(()=>{
      $('.img').on('mouseenter', (e)=>{
        let current = e.currentTarget;
        gsap.to('.img', {opacity:(i,t)=>(t==current)? 1:0.5, ease:'power3'})
      })
      $('.img').on('mouseleave', (e)=>{
        gsap.to('.img', {opacity:1, ease:'power2.inOut'})
      })
    }, '-=0.5')

$(window).on('mousedown touchstart', dragStart);
$(window).on('mouseup touchend', dragEnd);
      

function dragStart(e){ 
  if (e.touches) e.clientX = e.touches[0].clientX;
  xPos = Math.round(e.clientX);
  gsap.set('.ring', {cursor:'grabbing'})
  $(window).on('mousemove touchmove', drag);
}


function drag(e){
  if (e.touches) e.clientX = e.touches[0].clientX;    

  gsap.to('.ring', {
    rotationY: '-=' +( (Math.round(e.clientX)-xPos)%360 ),
    onUpdate:()=>{ gsap.set('.img', { backgroundPosition:(i)=>getBgPos(i) }) }
  });
  
  xPos = Math.round(e.clientX);
}


function dragEnd(e){
  $(window).off('mousemove touchmove', drag);
  gsap.set('.ring', {cursor:'grab'});
}


function getBgPos(i){ //returns the background-position string to create parallax movement in each image
  return ( 100-gsap.utils.wrap(0,360,gsap.getProperty('.ring', 'rotationY')-180-i*36)/360*500 )+'px 0px';
}



</script>
</body>
</html>

carousel image javascript src
2021-11-24 04:55:30
1

最好的答案

1

请检查的例子。 有几个编辑:

  • 更新的样式 .img { background-repeat: no-repeat; background-size: cover; background-position: 50% 50% !important;}
  • 收集 10 图像 const images = [...] -一个新的图像加入-"http://placehold.it/1263x710"请改变,以适当
  • 更新的图像:(i)=>url("${images[i]}")

let xPos = 0;
  const images = [
    "https://cdn.pixabay.com/photo/2017/01/08/13/58/cube-1963036__340.jpg",
"https://hatrabbits.com/wp-content/uploads/2017/01/random.jpg",
"https://cdn.pixabay.com/photo/2015/03/17/02/01/cubes-677092__480.png",
"https://www.destructoid.com/wp-content/uploads/2021/09/Lost-in-Random-Shadowman-screenshot.jpg",
"https://static1.srcdn.com/wordpress/wp-content/uploads/2021/03/Among-Us-Random-Name-Generator.jpg",
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTTL71W2u3jfYvvp2MXCfvVwHoyM-cioxCZkA&usqp=CAU",
"https://files.realpython.com/media/random_data_watermark.576078a4008d.jpg",
"https://uploads-ssl.webflow.com/5a9ee6416e90d20001b20038/5f248ec98e860a09db602367_random-object-generator%20(1).png",
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRB9VVgVQhCfCnD7udlz3tJnAR61x76JZ3Ftw&usqp=CAU",
"http://placehold.it/1263x710"
  ]

gsap.timeline()
    .set('.ring', { rotationY:180, cursor:'grab' }) //set initial rotationY so the parallax jump happens off screen
    .set('.img',  { // apply transform rotations to each image
      rotateY: (i)=> i*-36,
      transformOrigin: '50% 50% 1600px',
      z: -1600,
      backgroundImage:(i)=>`url("${images[i]}")`,
      backgroundPosition:(i)=>getBgPos(i),
      backfaceVisibility:'hidden'
    })
    .from('.img', {
      duration:1.5,
      y:200,
      opacity:0,
      stagger:0.1,
      ease:'expo'
    })
    .add(()=>{
      $('.img').on('mouseenter', (e)=>{
        let current = e.currentTarget;
        gsap.to('.img', {opacity:(i,t)=>(t==current)? 1:0.5, ease:'power3'})
      })
      $('.img').on('mouseleave', (e)=>{
        gsap.to('.img', {opacity:1, ease:'power2.inOut'})
      })
    }, '-=0.5')

$(window).on('mousedown touchstart', dragStart);
$(window).on('mouseup touchend', dragEnd);


function dragStart(e){
  if (e.touches) e.clientX = e.touches[0].clientX;
  xPos = Math.round(e.clientX);
  gsap.set('.ring', {cursor:'grabbing'})
  $(window).on('mousemove touchmove', drag);
}


function drag(e){
  if (e.touches) e.clientX = e.touches[0].clientX;

  gsap.to('.ring', {
    rotationY: '-=' +( (Math.round(e.clientX)-xPos)%360 ),
    onUpdate:()=>{ gsap.set('.img', { backgroundPosition:(i)=>getBgPos(i) }) }
  });

  xPos = Math.round(e.clientX);
}


function dragEnd(e){
  $(window).off('mousemove touchmove', drag);
  gsap.set('.ring', {cursor:'grab'});
}


function getBgPos(i){ //returns the background-position string to create parallax movement in each image
  return ( 100-gsap.utils.wrap(0,360,gsap.getProperty('.ring', 'rotationY')-180-i*36)/360*500 )+'px 0px';
}
html, body, .stage, .ring, .img {
  width:100%;
  height: 100%;
  transform-style: preserve-3d;
  user-select:none;
}

html, body, .stage {
  overflow:hidden;
  background:#000;

}

div, svg {
  position: absolute;
}

.container {
  perspective: 2000px;
  width: 1000px;
  height: 500px;
  left:50%;
  top:50%;
  transform:translate(-50%,-50%);
}

.img {
    background-repeat: no-repeat;
    background-size: cover;
    background-position: 50% 50% !important;
}
  <script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/3.6.1/gsap.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js'></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">

<div class="stage">


<div class="container">
  <div class="ring">
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
    <div class="img"></div>
  </div>
</div>

</div>

2021-11-27 08:55:56

我还需要增加<一个>的链接所有这些图像我已经应用的链接在<div class="img">部分,但它消失的圆盘传送带拖所以你能不能帮我出,如果可能的
Yash Chitroda

当然,只是添加数据属性每div- <div class="img" data-href="http://google.com"></div> 可以使用的那部分- window.location.href = e.target.dataset.href; 然后添加额外事件处理程序和isDragging标志,它可以用来检测如果这一点击或阻力。 例- codepen.io/alekskorovin/笔/yLzByPv
aleks korovin

兄弟,现在我试着要添加文件夹中的位置 ../<folder name>/index.html 但是,更换谷歌的链接,例如与上述法是不是实现我的目的我不得重提到页你可以帮我如果可能吗?
Yash Chitroda

请提供最新版本的问题
aleks korovin

只是和你一样的代码笔只是我想要的是而非的网页链接我需要增加本地链接到文件夹,我保存了html文件
Yash Chitroda

我能够使用这些链接 data-href="test2.html" -网页是相同的级别上的页面有你的旋转木马,如果它在另一个文件夹,你必须使用 data-href="./test-folder/test2.html"
aleks korovin

为什么不 ../test-folder/test2.html ?? 我用这个和这不是干活
Yash Chitroda

也试过 data-href="./test-folder/test2.html 但它不是工作呢
Yash Chitroda

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................