Copied to clipboard

Flag this post as spam?

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


  • marcus henriksen 6 posts 136 karma points
    Aug 19, 2015 @ 06:43
    marcus henriksen
    0

    Image slider / Carousel Problems. (bootstrap / carouFredSel)

    Hello. so im trying to make an imageslider for my Umbraco site.

    im currently trying to use this piece of code but it dosnt work, the correct images are, however, displayed but they just stack on top of eachother and dosnt slide or move atall.

    @inherits UmbracoTemplatePage
    
    @{
        var mediaFolderId = (int)CurrentPage.BannersMediaFolder;
    }
    
    @if (mediaFolderId > 0)
    {
        var mediaFolder = Umbraco.TypedMedia(mediaFolderId);
        var banners = mediaFolder.Children(x => x.DocumentTypeAlias == "Banner").ToList();
        var number = 0;
    
       <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
      <div class="carousel-inner  ">
                @foreach (var banner in banners)
                {
                    var link = Umbraco.TypedContent(banner.GetPropertyValue<int>("link"));
    
    
                        if (number >= 0)
                        {
                            <div id="item active">
                                <img src="@(banner.GetPropertyValue<string>("image"))"/>
                            </div>
                        } 
                        else
                            {
                            <div id="item">
                            <img src="@(banner.GetPropertyValue<string>("image"))"  />
                            </div>
                            }
    
                }
            </div>
        </div>
    
    }
    

    i thought it was a javascript problem however when i delete that code and paste in this simple version i have (with images from placehold.it) it works just fine with slide and everything.

    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
      <div class="carousel-inner  ">
    
        <div class="item active">
          <img  src="http://placehold.it/500x250" alt="...">
          </div>
    
        <div class="item">
          <img  src="http://placehold.it/500x250" alt="...">
        </div>
    
        <div class="item">
          <img  src="http://placehold.it/500x250" alt="...">
        </div>
      </div>
    </div>
    

    Anyone got an idea on what this could be? i think the actual code works ok, not 100 % ofc. it gets the correct images and so on. but yeah any tips would be appreciated. or if you are aware of a nice method to create a simple slider that would be grate. im having some real trouble with them. i also tried to use Caroufredsel slider ( the tutorial other people on this forum has linked to aswell http://carlosmartinezt.com/2014/06/umbraco-7-and-mvc-practical-examples-part-2/) but i couldnt get that to work so i tried to implement the bootstrap carousel slider Html instead and that is now where i am. (my javascript links are located on my masterpage template) -

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
                       <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    
  • Martin 114 posts 313 karma points
    Aug 19, 2015 @ 07:53
    Martin
    0

    Have you checked if any parent container may prevent proper sliding? For example if you have a main div with settings that may affect you slider.

    Good luck! /martin

  • marcus henriksen 6 posts 136 karma points
    Aug 19, 2015 @ 08:49
    marcus henriksen
    0

    Thank you Martin, but that doesn't seem to be it. :(

  • marcus henriksen 6 posts 136 karma points
    Aug 20, 2015 @ 06:32
    marcus henriksen
    100

    So i finally made it work with this Partial view code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using umbraco.MacroEngines;
    
    
    @{
    var mediaFolderId = (int)CurrentPage.BannersMediaFolder;
    }
    
    @if (mediaFolderId > 0)
    {
    
    
                var mediaFolder = Umbraco.TypedMedia(mediaFolderId);
                var banners = mediaFolder.Children(x => x.DocumentTypeAlias == "Banner").ToList();
                int i = 0;
        <div class="col-md-4 col-md-offset-4">
        <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
      <div class="carousel-inner  ">
                @foreach (var banner in banners)
                {
                    if (i ==0)
                    {
                        <div class="item active">
                            <img src="@(banner.GetPropertyValue<string>("image"))" />
                        </div>
                    }
                    else
                    {
                        <div class="item">
                            <img src="@(banner.GetPropertyValue<string>("image"))" />
                        </div>
                    }
                   i++;
                }
        </div>
            </div>
            </div>
    }
    

    a combination what i used before and some code from a post by Tom here on the forum.

Please Sign in or register to post replies

Write your reply to:

Draft