ไม่สามารถแทรกภาพต่างๆในท้องถิ่นม้าหมุน

0

คำถาม

ฉันทำงานกับม้าหมุนภาพนี้ผมต้องมีรหัสแต่มันเป็นตามจับอยู่ในนรหัสอะไรฉันต้องการคือการแทรก 9 หารค่า เหมือนกั ท้องถิ่นของภาพ/รูปภาพที่อยู่ url ขอ งแทนที่จะขอตรรกะ https://picsum.photos/id/'+(i+32)+'/600/400/ ใน backgroundImage:(i)=> แต่ตอนแทนคนเหนือ https:// เชื่อมโยงกับ เหมือนกั ท้องถิ่นของภาพ/รูปภาพที่อยู่ url น มีเพียงเดียวที่คล้ายกันภาพนั่นโผล่มาแล้วฉันโดยไม่รู้ว่าได้ยังไงฉันเพิ่หารค่ารูปภาพนั้นไม่ได้อีกในม้าหมุน

Eg ของภาพทั้งหมดที่ฉันต้องการจะแทรก

ภาพ 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"ได้โปรดเปลี่ยนมันให้เหมาะสม
  • ปรับปรุงของ backgroundImage:(ฉัน)=>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 ห้อง="img">ส่วนแต่มันจะหายไปใน carousal ดึงดังนั้นคุณสามารถแค่ช่วยฉันออกไปกับมันถ้าเป็นไปได้
Yash Chitroda

แน่นอนแค่เพิ่มข้อมูลของแอททริบิวต์ต่างๆต่อ divs- <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 แต่แทนของกูเกิ้ลเป็นเชื่อมโยง eg กับไวยากรณ์เหนือไม่ใช่ achieving เป้าหมายของฉัฉันไม่เคย redirected ต้องพูดถึงหน้าคุณสามารถช่วยฉันออกไปถ้าเป็นไปได้เหรอ?
Yash Chitroda

โปรดกำหนดของเวอร์ชั่นล่าสุดกับเรื่องที่สำคัญ
aleks korovin

มันแค่เหมือนกับคุณรหัสแค่ปากกาฉันต้องการคือแทนที่จะเป็นของหน้าเว็บที่ถูกเขียนด้วยที่อยู่เชื่อมโยงฉันต้องการเพื่อเพิ่มโฟลเดอร์ท้องถิ่นที่อยู่เชื่อมโยงไปซึ่งฉันต้องเก็บของแฟ้มเอกสาร htmlname
Yash Chitroda

ฉันสามารถใช้ที่อยู่เชื่อมโยงนั้น data-href="test2.html" -หน้าก็คือบอยู่ในระดับเดียวกับที่หน้ากับของม้าหมุนถ้ามันอยู่ในโฟลเดอร์อื่นคุณต้องใช้ data-href="./test-folder/test2.html"
aleks korovin

ทำไมจะไม่ได้ ../test-folder/test2.html ?? ฉันต้องใช้นี่แล้วมันไม่ใช่ workin
Yash Chitroda

ยังพยายาม data-href="./test-folder/test2.html แต่มันไม่ทำงานรึยัง
Yash Chitroda

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

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