Change column background on mouseover

Hi all,

In my project I’m using a strip that I selected from the ‘Add’ list. (under ‘Services’ → ‘What we do’). It’s showing the services in a number of columns. But I want people to be able to click them and go to another page. Unfortunately the Wix editor doesn’t provide linking a column itself, but I was able to fix this using Wix Code with the ‘onClick’ option.

What I would also like to do, is to create better visibility for the user by having the column (which basically looks like a button) change color when the cursor moves over it. What would in your opinions be the best way to go about this?

I’ve been playing around with the ‘onMouseIn’ and ‘onMouseOut’ options. I created a duplicate strip over the existing strip and hid it, and used ‘onMouseIn’ to display it. This didn’t work, somehow. I also looked into changing the html code, but couldn’t figure that out either. That’s about when I gave up and started asking you guys for help. Hope to hear from someone.

Cheers,
Dave

(and of course, a happy New Year to all!!)

You can’t change the colour of a column, you can only set the src, you can create your own image and then upload it and set the src.

What I did, is created a strip and added an interactive box (changes on mousein) box on it and use the onClick function along with wixLocation.to just an easy way to do it.

Hi Carlos,

Thanks for your fast reply. The reason for wanting to use the columns is firstly because the predesigned strip has them. And there you can assign backgroundcolor to each column using the Wix editor. So my assumption was that this could also be changed using code. One advantage of using columns is that they automatically distribute themselves.

So on the one hand I would love to find a solution for the columns because I somehow believe it should be possible. But to achieve my goal without excessive frustration and timeloss I will definitely try your approach with the interactive boxes. Thanks.

Hi Dave,

I was looking for the same thing and solved it with duplicating the strips and putting them on top of each other. It works, but it is not a nice solution and nearly made me move away to custom code the page. Now I actually hope that it will be fixed soon as columns are pretty new as well.

You’d have to use the mouseIn and mouseOut effects in combination with a (in the beginning) hidden strip that gets shown and hides the other strip at the same time. If you then use some time delays, you can get rid of most of the “flickering” that is generated by the switching - for me it looked quite awful otherwise.

The problem with using interactive hover boxes is that they don’t scale to the browser size. So you can’t put them in a column at 100% width, which makes it unusable for me.

Cheers, Mirko

@mirkoschedlbauer You have access to Column API functions that should help you out
Just use the column element ID…


Cheers
Steve

Hi @stevendc ,

true, but there is only the option of setting a background image and not to change the background color. Changing the image unfortunately always creates a slight delay.

I only found https://www.wix.com/code/reference/$w.Background.html#BackgroundOptions where there is no background color or opacity mentioned.

Do you know a workaround for that?

Best
Mirko

Hi Mirko,

Thanks for your reply. I’ve been playing around with the hidden strip as well. I couldn’t get that to work properly. Somehow the hidden strip was blocking the visible strip or something. Even when applying the mouseIn and mouseOut settings to both strips didn’t do the job for me.

I agree on the scaling issue with the hoverbox which is why I wanted the columns in the first place as well. But if I can’t easily get this to work properly, it’s not worth the hassle and I’ll just stay with the hoverbox.

Could you perhaps show my a bit of how you setup the mouseIn and mouseOut settings? And a piece of code?

@mirkoschedlbauer @[Dave de Groot] OK after playing around with this for a little while here is a work around:

Instead of using a strip element I used a repeater that contained two boxes each half of the width of the screen.


You can make the repeater full width by using the stretch control:


Now the trick is to figure out which of the container boxes has been selected in the mouseIn and mouseOut event.

You can do this by examining the repeater data property. This is an array that will be configured from the Manage Items property panel in the Editor.

So let’s build the onMouseIn() function as an example. We will do this all in code from here on in!
Start by defining the mouseIn handler in our page code onReady function:

$w.onReady(() => {
    $w('#box2').onMouseIn(box2_mouseIn);
});

function box2_mouseIn(event) {

}

Ok now lets get the repeater item list. Note: the repeater in the first screenshot is called #repeater2

let repeaterItems = $w('#repeater2').data;

Now we have the items list we now need to figure out which box on our repeater the mouse entered. We can do this by getting the item’s id from the event context like this:

let itemId = event.context.itemId;

Now we have the id we can figure out the index of the repeater data list by searching the repeaterItems list like this:

let repeaterIndex = repeaterItems.findIndex((item) => {
    return item._id === event.context.itemId
});

repeaterIndex should be 0 or 1 and you can then use this to modify the box background color. To do this we use the $w.at() function to get the repeater scope for the box from the event context.

let $repeaterScope = $w.at(event.context);

Now all we can use this to make the boxes different colors depending on which box was entered
so our mouseIn handler looks like this:

$w.onReady(() => {
     $w('#box2').onMouseIn(box2_mouseIn);
});

function box2_mouseIn(event) {
     let repeaterItems = $w('#repeater2').data;
     let itemId = event.context.itemId;
     let repeaterIndex = repeaterItems.findIndex((item) => {     
          return item._id === event.context.itemId
     });
     let $repeaterScope = $w.at(event.context);
     let boxElement = $repeaterScope('#box2');
     if (repeaterIndex === 0) {
         boxElement.style.backgroundColor = "red";
    } else {
         boxElement.style.backgroundColor = "orange";
    }
}

I’ll let you figure out the mouseOut and other configuration settings!

Cheers
Steve

Hi Steve,

thanks for the description. I just can’t get the boxes to fix perfectly. They don’t seem to be as accurate as columns in terms of being exactly 50% of the screen. We use those boxes exactly underneath each other and there was always an ugly little gap.

Dave de Groot , here is the code I currently use for hiding the strips:

$w.onReady(function () {
});

import wixLocation from “wix-location”;

let fadeInOptions = {
“duration”: 115,
“delay”: 0
};

let fadeOutOptions = {
“duration”: 0,
“delay”: 105
};

export function column1_mouseOut(event) {
$w(“#columnStrip”).show();
$w(“#columnStripHidden”).hide();
}

export function column2_mouseIn(event) {
$w(“#columnStripHidden”).show(“fade”,fadeInOptions);
$w(“#columnStrip”).hide(“fade”,fadeOutOptions);
}

export function columnStrip_click(event) {
wixLocation.to(“/PAGE”);
}

Hey Mirko and Steve,

Thanks for your extensive info. I’ll have something to try out tonight. I’m not much of a coder though, so it’ll take me some time to understand. But I’ll get there.

[@Mirko S.] I used the Toolbar to size the overlay box. Started by making sure the repeater was fully stretched. Then set the width of the box to half the repeater width (for me that was 800px - screen width 1600px).

@mirkoschedlbauer @Dave de Groot

You can try using the Column API as Steve mentioned and then use the desired solid color image in place of the background image.

Hope it helps