Swap BG gradient images in a gallery of swatches

蹲街弑〆低调 提交于 2020-04-07 09:14:14

问题


I am finishing a function to edit swatches in a grid,and am at the point where small image needs to be swapped with the main image to edit/alter if required, the current code gets the individual image, but not swap it with the main image. I have used .src, but this doesn't seem to be right for a gradient background image, should I use backgroundImage?. Code is below, and works until the swap, which doesnt. The mainID id is the large div at the top of the page "bodybg", where the swatch was created, and is supposed to go back there to edit.

editSwatch(){
let el = document.querySelectorAll('.swatch');
for(let i=0; i < el.length; i++) {
el[i].addEventListener('click', function () {
  el[i].setAttribute('id', 'gradient');      //id only on clicked swatch
  let mainID = document.getElementById('bodybg');
  let smallID = document.getElementById('gradient');
  // eslint-disable-next-line no-unused-vars
  let mainSRC = mainID.src;
  let smallSRC = smallID.src;
    mainSRC = smallSRC;        //doesnt work
    console.log('Clicked');    //works

  });
  }
}

So in short,a bg image swap, but with gradients not images? Any tips welcome

Demo: Demo Here

Thanks

来源:https://stackoverflow.com/questions/61034686/swap-bg-gradient-images-in-a-gallery-of-swatches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!