Coder Social home page Coder Social logo

Comments (5)

kennethcachia avatar kennethcachia commented on May 30, 2024

Hi!

I can't access the link anymore but I've noticed that you're using BackgroundCheck on http://julia.samambaia.co.uk/. The logo and nav links change color from slide to slide. Are you still experiencing this issue?

(No problem!)

from background-check.

ough- avatar ough- commented on May 30, 2024

Hi, I managed to fix it but I suspect it's not very clean. I basically called the functions again after each click/swipe/scroll:

$(document).ready(function() {
window.addEventListener('DOMContentLoaded', function () {
// Prepare BackgroundCheck
BackgroundCheck.init({
targets: '.target',
images: '.change'
});
});

$(document).on('click', function(e){
setTimeout(function(){
BackgroundCheck.refresh();
},300);
});

$(document).on('mousewheel', function(e){
setTimeout(function(){
BackgroundCheck.refresh();
},300);
});

$(document).on('keydown', function(e){
setTimeout(function(){
BackgroundCheck.refresh();
},300);
});

$(document).on('touchmove', function(e){
setTimeout(function(){
BackgroundCheck.refresh();
},300);
});

});

from background-check.

kennethcachia avatar kennethcachia commented on May 30, 2024

Makes sense.

init() is used to initialize the plugin and process the targets and images once. In addition, you need to call refresh() every time the position of the targets and/or images change.

You have two options when using sliders:

  • call refresh() after a timeout which must be >= to the duration of the slide transition
  • certain sliders fire an event or execute callback functions when a slide transition is ready which you can use to call refresh()

Swiper has an onSlideChangeEnd callback function - http://www.idangero.us/sliders/swiper/api.php.

Try the following:

Exclude javascripts/text-colour-fs.js from your site and rewrite your existing block:

var mySwiper = new Swiper('.swiper-container')
$('.arrow-right').on('click', function(e){
  e.preventDefault()
  mySwiper.swipeNext()
})

to:

$(document).ready(function() {
  // Initialize Swiper
  var mySwiper = new Swiper('.swiper-container', {
    onSlideChangeEnd: function() {
      BackgroundCheck.refresh();
    }
  });

  // Prepare BackgroundCheck
  BackgroundCheck.init({
    targets: '.target',
    images: '.change'
  });

  $('.arrow-right').on('click', function(e) {
    e.preventDefault();
    mySwiper.swipeNext();
  });
});

from background-check.

ough- avatar ough- commented on May 30, 2024

That worked a treat, thanks!

On a slightly different note, is it possible to have the script working on both background-image and background-color?

Thanks again

from background-check.

kennethcachia avatar kennethcachia commented on May 30, 2024

Awesome!!

At the moment, the plugin only supports images - using either <img> or CSS background-image.

from background-check.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.