0

I would like to do the same effect with the one below (may be with animate);

codepen sample cycle

HTML:

<html>    
<body>
  <section id="solutions" data-direction="from-left">
    <div class="container">
      <a href="#" class="close"></a>
      <div class="row solutionsRow">
        <div class="col-md-3 no-pad1">
          <div id="right1" class="pics">
            <img class="img-center" src="http://s33.postimg.org/k9sxc4hu7/smart_env.jpg" width="168" height="168" alt="Akıllı Çevre" />
            <ul class="solutions-ul">
              <li lang="tr">
                <i class="fa fa-caret-right"></i> Hava Kirliliği
              </li>
              <li lang="tr">
                <i class="fa fa-caret-right"></i> Orman Yangın Algılama
              </li>
              <li lang="tr">
                <i class="fa fa-caret-right"></i> Deprem Erken Teşhis
              </li>
              <li lang="tr">
                <i class="fa fa-file-image-o"></i> <a class="fancybox1" rel="gallery0" href="http://s33.postimg.org/yiy2aojm7/smart_world.jpg">Ek</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </section>
</body>

</html>

Javascript:

$(document).ready(function() {
  $("#right1").cycle({
    fx: 'scrollRight',
    next: '#right1',
    timeout: -3000,
    easing: 'easeInOutBack'
  });
  $(".fancybox1").fancybox({
    autoSize: true,
    fitToView: true,

  });
});

The reason is because I can NOT open fancybox when I click on the anchor inside of the UL while using cycle plugin. I do want to open fancybox and zoom.

Thanks in advance.

Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
Cenk
  • 13
  • 5

2 Answers2

1

LAST AND FINAL EDIT
  - Another satisfied client! lol!

For future SO readers:
The final solution is in this CodePen.

In short, this solution allows to use both cycle.js and FancyBox.js plugins "interacting" or "mixed together"... And the use of the FancyBox's "gallery" feature... And... and... and... The possibility to insert link to PDF (or anything!)

   ( Is there a term for plugin mix debugging? )

So you can read-on from the first answer and it's subsequential edits below:
(To fully understand how the solution works)



First answer:

I modified a couple things to you CodePen in order to make FancyBox usable with Cycle... Intead of trying to recreate the cycle effect with jQuery.

See this CodePen.

Explanations:

  1. I had to use 2 kitten images because yours weren't available.
  2. I added the FancyBox CSS CDN link (Was missing in your CodePen).
  3. I placed the image to use with FancyBox outside the #right1 div used with Cycle.js.
  4. I added some CSS to be able to see the rest of the text(in greek) and hide the image.
  5. I removed your FancyBox params, since not working (even when removing the extra coma)

autoSize: true,
fitToView: true,

  1. I added a click handler on the "Ek" link.
    It does these things:
    Show the hidden image,
    Simulate a click event on the link wrapping the image to trigger FancyBox.

HTML:

<section id="solutions" data-direction="from-left">
<div class="container">
  <a href="#" class="close"></a>
  <div class="row solutionsRow">
    <div class="col-md-3 no-pad1">
      <div id="right1" class="pics">
        <img class="img-center" src="https://upload.wikimedia.org/wikipedia/commons/1/11/Mihail_Manolov_-_Little_Kitten_(by-sa).jpg" width="168" height="168" alt="Akıllı Çevre" /><!--Original url for unavailable image: http://i.imgur.com/CtLbKCN.jpg?1-->
        <ul class="solutions-ul">
          <li lang="tr">
            <i class="fa fa-caret-right"></i> Hava Kirliliği<!--Air pollution-->
          </li>
          <li lang="tr">
            <i class="fa fa-caret-right"></i> Orman Yangın Algılama<!--Forest Fire Detection-->
          </li>
          <li lang="tr">
            <i class="fa fa-caret-right"></i> Deprem Erken Teş<!-- Earthquake Early Diagnosis-->
          </li>
          <li lang="tr">
            <i class="fa fa-file-image-o"></i> <a class="fancyBoxLink" rel="gallery0">EK</a>
          </li>
        </ul>
      </div>
    </div>
  </div>
        <a class="fancybox1" ><img class="imageToLink" src="https://c1.staticflickr.com/1/47/106442109_751ad0e91c.jpg"></a><!--Original url for unavailable image: https://i.imgsafe.org/7887214286.jpg-->
</div>
</section>

CSS:

.imageToLink{
  display:none;
}
.fancyBoxLink{
  color:dodgerblue;
  text-decoration:underline;
  cursor:pointer;
}
li{
  color:white;
}

Script:

$(document).ready(function() {
    console.log("page resetted");

    $("#right1").cycle({
        fx: 'scrollRight',
        next: '#right1',
        timeout: -3000,
        easing: 'easeInOutBack'
    });

    $(".fancyBoxLink").click(function(){    // click handler on EK link
        console.log("Click");
        $(".imageToLink").show();
        $(".fancybox1").click();
    });

    $(".fancybox1").fancybox();
});





EDIT

(After accepted answer and awarded bounty)

You asked a good question (in comments below)...
It deserves an edit.

To use my solution with many cycle.js instances, many links and use the FancyBox.js "gallery" feature

Its almost the same...
But from the clicked link, we have to determine:

  • Which cycle instance is the click's parent
  • What is the FancyBox class associated with it
  • What is the `eq()` argument to provide to trigger FancyBox on the right image

About the "associated with" class:
I used a custom attribute on the div used with cycle:
   <div id="right" class="pics" data-fancyBox_class="fancybox0">
This is supported by HTML5, reference here.

I had to create a "delayed" function to add click handlers to the dynamically created FancyBox prev/next icons in order to make the prev/next image displayed.

And, finally, I made a quick fix on the "click conflict".
(On link click, cycle triggers too...)

Most changes are in this script, see this updated CodePen.

$(".fancyBoxLink").click(function(){    // click handler on link
    console.log("Click")

    // Retreive the fancyBox picture gallery link class
    var thisFBclass = $(this).closest(".pics").attr("data-fancyBox_class");
    console.log("thisFBclass: "+thisFBclass);

    // determine which link has been clicked
    var thisLink = $(this).html();
    var linkEq;
    $(this).closest("ul").find("a").each(function(i,val){
        if( $(this).html() == thisLink ){
            linkEq = i;
            console.log("linkEq: "+linkEq); // `eq()` argument to provide
        }
    });

    $("." + thisFBclass + " .imageToShow").eq(linkEq).show();
    $("." + thisFBclass).eq(linkEq).click();

    // Quick fix about Cycle click triggered on the link click (click conflict)
    $(this).closest(".pics").click();

    // Call the prev/next show image function - 260ms delay is due to FancyBox time to execute.
    setTimeout(function(){
        dynamicPrevNextHandler();
    },260);
});

// Gallery prev/next handler
function dynamicPrevNextHandler(){
    console.log("dynamic prev/next handlers");
    $("body").find(".fancybox-prev").on("click", function(e){
        console.log("fancy-box-prev");

        // Show the FancyBox displayed image
        $("body").find(".fancybox-inner img").show();
    });
    $("body").find(".fancybox-next").on("click", function(){
        console.log("fancy-box-next");

        // Show the FancyBox displayed image
        $("body").find(".fancybox-inner img").show();
    });
}





EDIT

(Added PDF link feature)

Added script:

$(".PDFtrigger").click(function(){
    console.log("PDF!");
    var thisPDF = $(this).attr("href");
    console.log(thisPDF);
    window.open(thisPDF,"_blank");
});

How to define the link:

<a href="http://www.orimi.com/pdf-test.pdf" class="PDFtrigger">Akıllı Otopark - PDF</a>

See updated CodePen

BUG NOTE: Strangely, the window.open() function bugs in CodePen / Chrome 51... The new tab opens, but the document doesn't show. FireFox does behave correctly.

I tryed it as a local html file and Chrome doesn't bug. Also tryed it under FF47, IE11, Opera ==> All working good.

Safari 5.1.7 (for Windows) ==> Opens another window instead of another tab. And when you close this new window, Safari crashes. I just can't figure out why.

I just updated to Chrome 52... Problem remains within CodePen...

Community
  • 1
  • 1
Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
  • I will check and let you know my friend, thanks for your help. – Cenk Jul 24 '16 at 07:28
  • 1
    great job, thats exactly what I want. – Cenk Jul 25 '16 at 18:52
  • I will look forward to get your help for coming questions :) – Cenk Jul 25 '16 at 18:56
  • 1
    What if I have more than one to open? Would you please go to this [sample](http://www.ioterm.com/) site and navigate to our solutions? I would like to put link each of the cycles. – Cenk Jul 26 '16 at 08:32
  • did you check my sample web site? – Cenk Jul 26 '16 at 19:23
  • This script will work for you because it does not depends on how many `cycle` and `fancybox` instance you have. Starting point is the clicked link... It retreives the necessay info it needs by itself. (If you provided it in your HTML, of course!) ;) – Louys Patrice Bessette Jul 26 '16 at 20:55
  • What is imageToShow in the codepen? Same with imageToLink? – Cenk Jul 27 '16 at 07:27
  • Yep, I was right :) Is there any comments, suggestions for my sample web site? – Cenk Jul 27 '16 at 12:07
  • another what if :) What if I have image and pdf to display in the same cycle? – Cenk Jul 27 '16 at 14:06
  • hmm... For a pdf linked in a `cycle`, just don't give it the class`imageToShow` (or ImageToLink... sorry for the confusion). The fact that it does'nt have this class will make it to not "interfer" with the fancybox triggers. So give it a class name that will `display:none` on load. Then on click : toggle that class. I don't know if you want to present it as a modal, like the images... Or inline... Modal could be done too... But I would simply link it to display on another tab (as a full page pfd) using `target="_blank"` in the link So no class at all! I think it is better for reading... ;) – Louys Patrice Bessette Jul 27 '16 at 15:59
  • I am confused :) would you share the sample code please? – Cenk Jul 27 '16 at 18:01
  • did you mean like this? `Link` – Cenk Jul 28 '16 at 09:55
  • Simply use `Link` to open the PDF in a new tab. It won't interfer with the fancybox triggers. – Louys Patrice Bessette Jul 28 '16 at 17:05
  • I tried exactly like that inside of cycle but pdf did not open :( – Cenk Jul 28 '16 at 17:30
  • 1
    I wish I could give more bounty but I don't have enough privildges. – Cenk Jul 28 '16 at 18:24
  • Updated the solution, my friend. Have a look. ;) – Louys Patrice Bessette Jul 29 '16 at 15:22
  • PDF works but somehow image click doesn't pop up fancybox. – Cenk Jul 30 '16 at 14:28
  • Could you place the solution in [your sample site](http://www.ioterm.com/) so I could see what's going on for real ? Or create another "temp" sample-site... Give me a live link and we'll fix this. ;) – Louys Patrice Bessette Jul 30 '16 at 18:11
  • 1
    my bad my friend, I had to refresh and rebuild the solution. Now it works like a charm! :) thank u again, you saved the day! – Cenk Jul 30 '16 at 18:39
  • @LouysPatriceBessette PDF documents can be also be opened in fancybox so you don't have to call a `window.open()` popup, which can be a bit more intrusive ;) – JFK Oct 01 '16 at 19:47
0

this is a raw approach but could give you some ideas...

HTML:

<html>  
    <style>
        li{
            display: none ;
            border: 2px solid blue ;
            height: 250px ;
            width: 250px ;
        }
    </style>
<body>
  <section id="solutions" data-direction="from-left">
    <div class="container">
      <a href="#" class="close"></a>
      <div class="row solutionsRow">
        <div class="col-md-3 no-pad1">
          <div id="right1" class="pics">
            <ul class="solutions-ul">
                <li>
                    <img class="img-center" src="http://s33.postimg.org/k9sxc4hu7/smart_env.jpg" width="168" height="168" alt="Akıllı Çevre" />
                </li>
                <li lang="tr">
                    <i class="fa fa-caret-right"></i> Hava Kirliliği
                </li>
                <li lang="tr">
                    <i class="fa fa-caret-right"></i> Orman Yangın Algılama
    \           </li>
                <li lang="tr">
                    <i class="fa fa-caret-right"></i> Deprem Erken Teşhis
                </li>
                <li lang="tr">
                    <i class="fa fa-file-image-o"></i> <a class="fancybox1" rel="gallery0" href="http://s33.postimg.org/yiy2aojm7/smart_world.jpg">Ek</a>
                </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </section>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js.js" type="text/javascript"></script>
</html>

JS:

$(document).ready(function() {
    let arr = $("#right1").find("li");
    let i = 0;
    var showInterval;

    animation();

    function animation(){
        $(arr[i]).hide();
        (i < arr.length) ? (i++) : (i = 1);
        $(arr[i-1]).show();
            $(arr[i-1]).animate({width: "250px"}, 1400, function(){
                showInterval = setTimeout(function(){
                    if($(arr[i-1]).width() < 400){
                        $(arr[i-1]).hide();                      
                        $(arr[i-1]).css({width: "0px"});
                        animation();
                    }
                },2000);
            });
    }

    $("li").click(function(){
        $(this).stopPropagation;
        if($(this).width() == 250){
            clearTimeout(showInterval);
            if($(this).find("#close").length != 0){
                $(this).remove("#close");
            }
            else{
                $(this).html("<button id='close'>close</button>" + $(this).html())
            }
            $(this).clearQueue();
            $(this).show();
            $(this).animate({width : "500px", height : "500px"},500);   
        }
    });

    $(document).on("click", "#close", function(){
        if($(this).parent().width() == 500){
            $(this).parent().animate({width: "0px", height : "250px"}, 100, function(){
                $(this).hide();
                $(this).clearQueue();
                animation();
            });
            $(this).remove();
        }
    });


});
DIEGO CARRASCAL
  • 1,999
  • 14
  • 16
  • Can I open fancybox and zoom with this approach? – Cenk Jul 19 '16 at 04:59
  • Try it with the second JS, the `$("li").click(function(){...` could include the code for it... – DIEGO CARRASCAL Jul 19 '16 at 13:33
  • I'm doing it by animating the width, but you could also animate the position and make it slide from the left for example... The anchor inside should work just fine. – DIEGO CARRASCAL Jul 19 '16 at 14:41
  • can u also post the position animate? I will check both and let you know. – Cenk Jul 19 '16 at 14:47
  • well you just change the `animate({width:...` for `animate({left:` and set the CSS to `position:absolute;` or `animate({margin-left:` with the correct margin... – DIEGO CARRASCAL Jul 19 '16 at 15:10
  • there is nothing related with close button my friend. Would you please go to [link] (http://www.ioterm.com/) and navigate to our solutions. This is live and if I figure out how to open fancy box and zoom on image, I would like to put it here. – Cenk Jul 20 '16 at 06:51
  • 2
    Well, the thing is that this is not a free solution for you to implement in your web, is an example of an approach to solving your problem, you are supposed to take the code and modifies to serve your purpose. The close button is just a way to make the example more complete, so you see that the animation continue when resizing the `
  • `. (a bounty is not payment for a working and complete solution to your problem). Sorry.
  • – DIEGO CARRASCAL Jul 20 '16 at 15:59