I am trying to customize the Divi
theme for WordPress.
In this project: http://dm-wp.com/vins-lelievre/, I’d like to have the logo and the menu color change to white if the active slide background is dark.
I would like to add a class to the body if the new active slide has the class “et_pb_bg_layout_dark”.
Function already exists for adding color class to the slider container.
I think what I am missing is the event that makes the script run again to check the condition.
Can I insert the script in the integration field of the theme or shall I edit theme .js file?
From my investigations, script would look like this.
I guess it’s wrong or not complete:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery( document ).ready(function() {
if ( jQuery('#slide-home').hasClass( "et_pb_bg_layout_dark" ) ) {
jQuery('body').addClass('yourClassName');
}
});
</script>
Thanks for your help
3
Answers
This is the slider structure, where 'et_pb_bg_layout_light' is actually changed for 'et_pb_bg_layout_dark' inside 'et_pb_slider ' if 'et_pb_slide' has 'et_pb_bg_layout_dark'. Only CSS classes, I added the ID '#home-slide', but theoritically it shouldn't be necessary.
You didn’t have
<div id="slide-home"></div>
in your code.When you click on
button
, if#slide-home
has class.et_pb_bg_layout_dark
, the background of body will changeHere is a piece of the original visual builder javascript where I think I can find similar functions to the one I want to have. For example “et_slider_auto_rotate()” or the variable “tabs_animation”. Anyone inspired to explain me how it works to get classes checked and added or removed on every slide change?