Copied to clipboard

Flag this post as spam?

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


  • Philip Christianto 20 posts 150 karma points
    Jul 02, 2017 @ 14:47
    Philip Christianto
    0

    Umbraco dynamic slide show with cycle2.js

    im making a dynamic site using umbraco and need a slide show for it.

    The slideshow will be dynamically created depending on the number of children in the content

    the full code for creating it dynamically is

    @foreach (var item in items.Children){
    var carouselLeftID = item.Name.Replace(" ", String.Empty) + "Left";
    var carouselRightID = item.Name.Replace(" ", String.Empty) + "Right";
    var carouselLeft = "#" + item.Name.Replace(" ", String.Empty) + "Left";
    var carouselRight = "#" + item.Name.Replace(" ", String.Empty) + "Right";
    <a href=# id="@carouselLeftID"></a>
    <a href=# id="@carouselRightID"></a>              
    <div class="cycle-slideshow"
         data-cycle-fx=carousel
         data-cycle-timeout=10000
         data-cycle-carousel-visible=3
         data-cycle-carousel-fluid=true
         data-cycle-next="@carouselRight"
         data-cycle-prev="@carouselLeft"
         data-cycle-slides="> .featureCarousel">
        @{
            foreach (var featureItems in item.Children)
            {
                dynamic featureIcon = Umbraco.Media((int)featureItems.iconImage);
                <div class="featureCarousel">
                    <div class="row featureItemRow">
                        <div class="col-md-12">
                            <div class="row ">
                                <div class="col-md-12">
                                    <img class="featureItemsIcon" src="@itemIcon.umbracoFile"  />
                                </div>
                                <div class="col-md-12">
                                    @featureItems.Name
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            }
        }
    </div> }
    

    somehow the button for next and prev slide doesnt work

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Jul 02, 2017 @ 17:06
    Marc Goodson
    1

    Hi Philip

    It's hard to be certainly what type of slideshow you are aiming for and to therefore be sure where the issue exactly is but, looking at a sample next previous slideshow on cycle2.js site:

    http://jquery.malsup.com/cycle2/demo/prevnext.php

    The markup should look something like this:

       <div id=outside>
        <!-- prev/next links -->
        <div class=center>
            <span id=prev>&lt;&lt;Prev </span>
            <span id=next> Next&gt;&gt;</span>
        </div>
        <!-- slideshow -->
        <div class="cycle-slideshow" 
            data-cycle-fx=scrollHorz
            data-cycle-timeout=0
            data-cycle-prev="#prev"
            data-cycle-next="#next"
            >
            <img src="http://malsup.github.io/images/p1.jpg">
            <img src="http://malsup.github.io/images/p2.jpg">
            <img src="http://malsup.github.io/images/p3.jpg">
            <img src="http://malsup.github.io/images/p4.jpg">
        </div>
    </div>
    

    So if you current item, has multiple children that form the slides then you don't need to include the next and previous buttons in the loop through these items, whereas in your sample it appears they are being repeated for each item? but that may be because I'm not getting what you are trying to achieve!

    So I think your code I'm thinking should be more like this:

           <div id=outside>
            <!-- prev/next links -->
            <div class=center>
                <span id=prev>&lt;&lt;Prev </span>
                <span id=next> Next&gt;&gt;</span>
            </div>         
    <div class="cycle-slideshow"
         data-cycle-fx=carousel
         data-cycle-timeout=10000
         data-cycle-carousel-visible=3
         data-cycle-carousel-fluid=true
         data-cycle-next="#next"
         data-cycle-prev="#prev"
         data-cycle-slides="> .featureCarousel">
    
            @foreach (var featureItems in item.Children())
            {
                dynamic featureIcon = Umbraco.Media((int)featureItems.iconImage);
                <div class="featureCarousel">
                    <div class="row featureItemRow">
                        <div class="col-md-12">
                            <div class="row ">
                                <div class="col-md-12">
                                    <img class="featureItemsIcon" src="@itemIcon.umbracoFile"  />
                                </div>
                                <div class="col-md-12">
                                    @featureItems.Name
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            }    
    </div> 
    </div>
    

    but may I'm simplifying and you have multiple carousels within carousels or something on the same page?

    eg what does items.Children() refer to in terms of your Umbraco structure?

    regards

    Marc

  • Philip Christianto 20 posts 150 karma points
    Jul 02, 2017 @ 17:26
    Philip Christianto
    0

    so for example there is a product i have

    the product is made of different parts

    each parts is used for something

    product

    part A

    Part A function 1

    Part A function 2

    Part A function 3

    part B

    Part B function 1

    Part B function 2

    Part B function 3

    So in the page i have part A name and the slide show of the functions

    also part B and so on

    the first foreach is used for the part list and the 2nd is for the part functions.

  • Philip Christianto 20 posts 150 karma points
    Jul 02, 2017 @ 17:46
    Philip Christianto
    100

    ah sorry i found the problem.

    i use a link as the anchor instead of span which make it go to the href if i click it

    sorry for the trouble

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Jul 02, 2017 @ 19:34
    Damiaan
    1

    You marked your own answer as a solution, while all the examples of Marc are with a span (and not an A tag).

    I hope you are kind enough to give him at least a hi-five, a written "thank you very much" or even mark it as a solution... Or all of them together.

  • Philip Christianto 20 posts 150 karma points
    Jul 02, 2017 @ 19:40
    Philip Christianto
    0

    done :3

Please Sign in or register to post replies

Write your reply to:

Draft