Hello super beings.
is it possible to connect the background image in a column on a dynamic page to the relevant photo in the dataset so that it too changes with the other elements?
Hello super user.
while the background property of a column isnât exposed through the connect dialog, you can do that with a bit of JS code.
take a look at the API reference on columns: Column - Velo API Reference - Wix.com
it should point you in the right direction.
good luck!
Does it show how to add JS code in any tutorial?
This tutorial shows the basics of adding scripts to your page:
https://www.wix.com/alpha/resources#!add-interactions/pvoe0
for your specific case, what you need to do:
- select your dataset in your dynamic page
- open the properties panel (tools ==> properties panel)
- hover over âonCurrentIndexChangedâ in the events list
- click the â+â sign to create an event handler. this is where you will write your image-setting logic.
this event is called by the wixcode runtime whenever the âactive recordâ in the dataset changes.
you can read about it more in the API reference. - write the code that changes the background image by accessing the image URL from the active record in the dataset and setting it into the background property of the column component.
your code should look similar to:
- let image_url = $w(â#myDatasetâ).getCurrentItem().myImageURL; //assuming you store image URLs in a field called my image URL .
- $w.(â#myColumnâ).background.src = image_url;
hope this helpsâŚ
Note that â$w.(â #myColumn â).background.src = image_url;â above should actually be â$w(â #myColumn â).background.src = image_url;â
Hi guys, thanks for the help.
i am trying to implement this according to Zivâs instructions but iâve realised the columns element is on a strip and itâs the strip background that i need to change depending on the service. how do i access this element and implement the change?
is it possible to add more than one dataset to a page. for instance on my homepage i have several strips. one such strip is for services and one is for testimonials. i have successfully linked the gallery on the testimonial strip to the testimonial dynamic page and dataset. but i now want to link the columns on my services strip to my services dynamic page and dataset. can i do both? i tried copying the dataset icon and changing it and it gave me a warning message. as you see below.
yes, it is possible to have more than one dataset on a page.
you need to add a new dataset through the add panel, configure it to point to the desired collection, and if relevant define filter conditions and sort order to determine which records are retrieved from the collection and in what order.
once the dataset is configured, you can connect it to visual elements just as you would for the dynamic dataset on the page.
Take a look at these articles to get the full understanding of using datasets:
https://support.wix.com/en/article/wix-code-articles-list#data-binding
Good luck!
As for your request to change the stripâs background, this is not currently exposed through our API.
If you can add this as a feature request to the feature request forum, it would be great.
thanks!
Hello, I am trying to change the background of a strip using an element from my database. The dataset is called, âportfolioDataset,â the strip is called âscreenshotStripâ and the database element is called âscreenshot.â
I have put the following code into my page, but I continue to get the error, âbackground is undefinedâ and the background of the strip does not change.
Can you help me understand why this isnât working, and how to fix it?
$w.onReady(function () {
$w(â#portfolioDatasetâ).onReady(function(){
$w(â#screenshotStripâ).background.src = $w(â#portfolioDatasetâ).getCurrentItem().screenshot;
});
});
If you take a look at our API Reference youâll see that a ColumnStrip element does not expose a background property. However a Column element does have a background property. So, if it works for your case, you can set the background of each individual column in your strip.
Thank you! I was able to get it fixed.
Hey Guys! I am using a column as a slideshow linked to buttons that when clicked changes the column background. It works great on desktop but doesnât work on tablet/iPad. Also having the same issue doing this with a page background. Any suggestions?
Hi,
Can you please re-post your question in a new thread?
Moreover, please share with us the code youâve written.
Thanks,
Tal.
Thanks Tal! I have posted it here: https://www.wix.com/code/home/forum/questions-answers/column-background-and-page-image-change-not-working-on-ipad