Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jonas Gunnarsson 44 posts 194 karma points
    Feb 17, 2014 @ 09:57
    Jonas Gunnarsson
    0

    Need help with slideshow

    Hi,

    I have a full screen slideshow on the front page in javascript, and would like to use multiple media picker to pick my images for the slideshow.

    The javascript code:

    var slidefade = 2000

       $.vegas('slideshow', {

            delay: 8000,

            backgrounds: [

              { src: '/media/1006/image1.jpg', fade: slidefade },

              { src: '/media/1007/image2.jpg', fade: slidefade },

              { src: '/media/1008/image3.jpg', fade: slidefade },

              { src: '/media/1009/image4.jpg', fade: slidefade },

              { src: '/media/1010/image5.jpg', fade: slidefade },

              { src: '/media/1011/image6.jpg', fade: slidefade },

              { src: '/media/1012/image7.jpg', fade: slidefade },

            ]

        })('overlay')

    I use multiple media picker in my portfolio, and it works well but I do not know how to code when it comes to scripting.

    @{
    var mediaID1 = Model.Content.GetProperty("images").Value.ToString().Split(',');
                }
                @foreach (var mediaID in mediaID1)
                {
                    var media = umbraco.uQuery.GetMedia(mediaID);
                    <div class="photo">
                        <a href="@media.GetImageUrl()" rel="shadowbox[gallery]"><img class="small-image" src="@media.GetImageUrl()" /></a>
                    </div>
                }

     

    //Jonas

  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 17, 2014 @ 10:24
    Fuji Kusaka
    0

    Hi Jonas 

    In your cshtml file do something like this for your js to work

    @{
    var mediaID1 = Model.Content.GetProperty("images").Value.ToString().Split(',');
             @:$.vegas('slideshow', {
        @: delay: 8000, 
            @: backgrounds: [
                @foreach (var mediaID in mediaID1){
                    var media = umbraco.uQuery.GetMedia(mediaID);
                   @:{src: '@media.GetImageUrl()', fade: slidefade }                
                }
    @:] @:})('overlay')
  • Jonas Gunnarsson 44 posts 194 karma points
    Feb 17, 2014 @ 10:40
    Jonas Gunnarsson
    0

    Thanks, but I get this error

    nexpected "foreach" keyword after "@" character.  Once inside code, you do not need to prefix constructs like "foreach" with "@".
    Line 39:             @: delay: 8000, 
    Line 40:         @: backgrounds: [
    Line 41: @foreach (var mediaID in mediaID1){ Line 42:                 var media = umbraco.uQuery.GetMedia(mediaID);
    Line 43:         @:{src: '@media.GetImageUrl()', fade: slidefade } 

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 17, 2014 @ 11:06
    Fuji Kusaka
    0

    Remove the @ sign before the foreach.

  • smajl 1 post 21 karma points
    Feb 17, 2014 @ 11:27
    smajl
    0

    Jonas: The error said it clearly.. next time, read the error message twice and try to think about it for couple of seconds.. Maybe it will be much quicker then writing into the forums and waiting for the reply. Just my advice. ;)

  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 17, 2014 @ 11:30
    Fuji Kusaka
    0

    @ Jonas: Did you get it working ?

  • Jonas Gunnarsson 44 posts 194 karma points
    Feb 17, 2014 @ 13:08
    Jonas Gunnarsson
    100

    @ Smajl, you're right, I should have checked the error message more carefully.

    @ Fuji: Sorry I have not responded, had to go away for a while. It still does not work, I get no error message but no images.Getting error in firebug that slidefade is not defined. Have tried to define it but have not really gotten it to work. But I get the correct paths to the images, so that bit works.

    Final code:

     @{
            var mediaID1 = Model.Content.GetProperty("images").Value.ToString().Split(',');
            @: var slidefade = 2000;
            @:$.vegas('slideshow', {
                @: delay: 8000,
            @: backgrounds: [
                foreach (var mediaID in mediaID1){
                    var media = umbraco.uQuery.GetMedia(mediaID);
    
            @:{src: '@media.GetImageUrl()', fade: slidefade },
        }
        @:]
            @:})('overlay')
            }

    Edit: I got it work now! Thank you so much for your help Fuji!

  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 17, 2014 @ 13:14
    Fuji Kusaka
    0

    Great if you got it working.

Please Sign in or register to post replies

Write your reply to:

Draft