Link Text with Swipe Gallery

436 views
Skip to first unread message

tob...@42digital.de

unread,
Sep 19, 2014, 7:02:44 AM9/19/14
to gwd...@googlegroups.com
Hey all,

Im searching for a way to connect the current Image of a Swipe Gallery to a certain Text(div). If I move the Swipe Gallery forwards or backwards the text should change while matching the Image as well.

Any feedback will help.

Thanks

danburton

unread,
Sep 22, 2014, 2:41:05 PM9/22/14
to gwd...@googlegroups.com
Swipe Galleries provide an event called "frame shown" which allows you to trigger an action every time a frame of the gallery is shown.

For example:

1. Copy the gallery's ID to your clipboard.
2. Right click on the gallery on the stage and click "add event"
3. [Event] Under "Swipable gallery" click "Frame shown"
4. [Action] Under "Custom" click "Add custom action"
5. Enter a javascript name for this custom action (for example: refreshText)
6. Write something like the following code:

var gallery = document.getElementById('gwd-swipegallery_1');
var div = document.getElementById('my-div');
var text = {
  1: "The text for frame 1",
  2: "The text for frame 2",
  3: "The text for frame 3"
};
div.textContent = text[gallery.currentIndex];

Paste your gallery's ID in place of 'gwd-swipegallery_1', and replace 'my-div' with your div's ID.

digital

unread,
Sep 23, 2014, 3:26:25 AM9/23/14
to gwd...@googlegroups.com
Thanks for your reply I will test it today.

stevej...@gmail.com

unread,
Jul 22, 2015, 4:47:51 PM7/22/15
to Google Web Designer beta
To do the same thing with text as images, or images in general you would do this:

var gallery = document.getElementById('gwd-swipegallery_1');
var div = document.getElementById('my-div');
var text = {

1: "<img src='assets/headline1.png'>",
2: "<img src='assets/headline2.png'>",
3: "<img src='assets/headline3.png'>"
};
div.innerHTML = text[gallery.currentIndex];
};

Make sure you use innerHTML

Reply all
Reply to author
Forward
0 new messages