sneas / img-comparison-slider

Image comparison slider. Compare images before and after. Supports React, Vue, Angular.
https://img-comparison-slider.sneas.io
MIT License
657 stars 47 forks source link

Use custom divider #131

Closed squidiw closed 11 months ago

squidiw commented 11 months ago

Hi, wanted to know if there’s a way I can use a custom divider ? For example an svg?

Currently the options are to modify the existing divider but not change it entirely like how the handle can be changed by using slot=handle

sneas commented 11 months ago

There is no option to use a custom divider at the moment. What kind of divider would you like to use?

squidiw commented 11 months ago

Something like this from a generator - https://kovart.github.io/dashed-border-generator/

Screenshot 2023-12-18 at 8 55 41 AM

And this is a png of it Line_130

squidiw commented 11 months ago

In the future if anyone wants to change the divider, what I ended up doing is,

const slider =  document.querySelector('img-comparison-slider');
  if(slider){
    setTimeout(() => {
      let sliderDivider = slider.shadowRoot;
      let styleSheet = document.createElement('style');
      sliderDivider.insertBefore(styleSheet, sliderDivider.children[0]);

      let rules = [
        `.divider{border:none;width:2px!important;}`,
        `.divider:after{border:none!important;width:2px;background-repeat:repeat-y;background-image:url("data:image/png;base64,........");}`
      ]

      rules.forEach((rule, index) => {
           styleSheet.sheet.insertRule(rule, index);
      })
    }, 1000);
  }