Hi Wixers,
I want to have specific words in a text box to underline on hover.
If possible, also to link a word with an .svg object to also show on hover.
similar to this:
The easiest path to the same effect is creating all the text elements separated, and use the onMouseIn() and onMouseOut() methods of such elements.
$w.onReady(() => {
$w('#txtNose, #txtEar, #txtMouth').onMouseIn(({ target }) => {
//Change those IDs above to the ones you are going to manipulate
let text = target.id.replace('txt', 'line')
highlightLine(text)
//You can put here the image you want to display when the mouse is in
})
$w('#txtNose, #txtEar, #txtMouth').onMouseOut(({ target }) => {
let text = target.id.replace('txt', 'line')
$w(`#${text}`).hide()
})
})
function highlightLine(text) {
let lines = ['lineNose', 'lineEar', 'lineMouth']
lines.forEach((line) => {
line === text ?
$w(`#${line}`).show() :
$w(`#${line}`).hide()
})
}
Thank you @Bruno Prado
I have a lot of text so creating a separate box for each word would be inefficient.
What I did is creating a container box for the mouse in and a line object for the underlying.
The problem is that the line objects keep changing location slightly Evan that I do not change anything. Another problem is that each browser randers the text slightly differently such that it is not aligned well with the line object.
I am sure the right way to do it is to modify the text itself but not sure how to do it on the wix editor.
Cheers,
Nadav
@nadavari one thing you can do is to create a box on top of the text you want to highlight and hide the line underneath and create a onMouseIn() on the box itself.
@bwprado Using different boxes and elements is what I did but because text is rendered differently in each browser they would not align properly.
I ended up converting each text box to svg and reupload as an svg object, no very efficient but it works.
Thanks for the help!
Hi @ahmadnasriya , Thanks for the help!
It is good to know about this option. But for me I will need to also be able to modify the colors and other properties.
I ended up converting each text box to svg and reupload as an svg object, no very efficient but it works.