Okay
  Public Ticket #163849
Javascript
Closed

Comments

  • Elisa started the conversation
    I want to change the site background color according to slide image? How can i do that? i tried to add some Javascript instead of text to the slide but this doesn´t work. In fact it should fade between the colors. Can you give me a hint? document.getElementById(body).style.background ='#cccccc';
  • Elisa replied
    I tried that: <script language="javascript">
    document.getElementById(sortimentmenu).style.background ='#cccccc';
    </script>

     

  •  948
    Max replied

    Hi, you can use slider's javascript api, and on the slide change function get the slide number, and set the color according the slide number. Please check the slider api in slider settings page. 

     

  • Elisa replied

    Hello Max, thank you!

    i tried to paste this:  <script type="text/javascript">     revapi1.revcurrentslide();             </script>  in output.class.php 

    seems not to be the right way to use the api. 

    Can you give me a hint?

    thanks,

     

  • Elisa replied

    I just tried this in a seperate .js file:

    		var getslide = revapi1.revcurrentslide();
    function menucolor () {
      if (getslide == 1) {
        document.getElementById('sortiment').style.backgroundColor = '#00ff00';
      } 
      else {
        document.getElementById('sortiment').style.backgroundColor = '#ff0000';
      }
    }
    menucolor ();	

    but i think again in the wrong file. Maybe the code is right, but i don´t know where to put it in...

     

    thanks again!

  • Elisa replied

    Hello Max,

    it´s getting more clear for me. But if i paste the content of the API in my templates .js i get an error in my console.

    This is what i pasted:

    revapi1.bind("revolution.slide.onchange",function (e,data) {
        alert("slide changed to: "+data.slideIndex);
    });

    Error: "ReferenceError: Can't find variable: revapi1
    global code script.js"

     

    If i paste it at the bottom of the body it says:

    TypeError: 'undefined' is not an object (evaluating 'revapi1.bind')

  •   Max replied privately
  •   Elisa replied privately
  •   Max replied privately
  •   Elisa replied privately
  •   Max replied privately
  • Elisa replied

    Hello Max,

    i just put in your lines and saved. Now the file should be ok the be saved.

    thank you,

    Elisa

  •  948
    Max replied

    Hi, please call the doSliderAPI from the script.js file from the front end from the end of the template. The problem is that the function is called before the revapi is created. Another option is to call it after some timeout. 

    like setTimeout(doSliderAPI,2000)

    everything else is normal copy / paste from slider options. 

    do you understand the solution? 

  •   Elisa replied privately
  •   Max replied privately
  •   Elisa replied privately
  •   Max replied privately
  •   Elisa replied privately
  •   Max replied privately
  •   Elisa replied privately
  •   Max replied privately
  •   Elisa replied privately
  •   Max replied privately
  •   Elisa replied privately
  •   Max replied privately
  • Elisa replied

    Hello Max! Thanks, done :-)