CSS - Flip image

user4433485

I am trying to flip images wich are dragged by using jquery when I drag the image to the new div, it makes a class. I use ui.helper.addClass("gemaakt"); and it's working fine! The thing is, my CSS script is flipping images etc.. but not classes for some reason? Since I drag those images, it puts them into a class

quite difficult to explain, so I decided to post it on JSfiddle so you can get see it,

http://jsfiddle.net/qbvzwsg2/ http://jsfiddle.net/qbvzwsg2/2/ <- updated version

As you can see, the flip ( at bottom, works correctly ) When click on image, it flips flawless, no problem.

But now, drag a card into the box, and click on that image.. Nothing happens :(

<div class="flip-container">
    <div class="flipper" onclick="this.classList.toggle('flipped')">
        <div class="front">
            <div class="ui-draggable gemaakt dropped"> </div>
        </div>
        <div class="back">
            <img src="./img/test.jpg">
        </div>
    </div>
</div>

for some reason it can not flip a class

Help someone? :D

falsarella

Persijn is correct. The image don't flip. What flips is the entire container, as in the card at the bottom:

<div class="flip-container">
    <div class="flipper" onclick="this.classList.toggle('flipped')">
        <div class="front">
            <div class="ui-draggable gemaakt dropped"> </div>
        </div>
        <div class="back">
            <img src="./img/test.jpg">
        </div>
    </div>
</div>

So, to make things happen, you could change the HTML of .cards img to accomplish that structure and change the draggable to .cards .flip-container.

To make it more easy to show you the fiddle, I just added this script to prepare the correct structure, instead of changing the HTML:

$(".cards img").each(function() {
    $(this).wrap('<div class="front"></div>').parent().wrap('<div class="flipper"></div>').parent().wrap('<div class="flip-container"></div>').append('<div class="back">FLIPPED</div>');
});

Then, with the correct structure, I changed the draggable to the .flip-container, as I mentioned above:

$(".cards .flip-container").draggable({

And changed its stop handler to make the card flippable when dropped at the correct place, by adding the onclick callback:

stop: function (event, ui) {
    ui.helper.removeClass("draggable");
    var imgSrc = ui.helper.find("img")[0].src.split("/");
    var image = imgSrc[imgSrc.length - 1];
    if ($.ui.ddmanager.drop(ui.helper.data("draggable"), event)) {
         ui.helper.find(".flipper").attr("onclick", "this.classList.toggle('flipped')");            
    } else {

    }
}

Finally, added that styling to don't break the look and feel:

.flip-container, .front, .back {
    display: inline-block !important;
    height: 150px !important;
}
#dvDest img {
    margin: 0px !important;
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Flip an image vertically

분류에서Dev

css3 card flip hover and click conflict

분류에서Dev

Flip random elements on a page in JS using CSS classes

분류에서Dev

CSS Align image with input

분류에서Dev

Image Masking using css

분류에서Dev

Text over Image CSS

분류에서Dev

resize image using css

분류에서Dev

background-image with css

분류에서Dev

CSS Responsive background image

분류에서Dev

How to do infinite animated flip of two-faced image using Jquery settimeout function

분류에서Dev

CSS3 Flip 기능 (뒷면 가시성 문제)

분류에서Dev

CSS Flip 애니메이션이 제 시간에?

분류에서Dev

Flipboard를 닮은 CSS Flip 애니메이션

분류에서Dev

HTML/CSS - image over image with parallax effect

분류에서Dev

HTML CSS Hover Image Link with One Image

분류에서Dev

css: alignment issue with image and header

분류에서Dev

Fullscreen responsive background image in CSS

분류에서Dev

CSS image overlay with color and transparency

분류에서Dev

CSS Color Overlay on Image Hover

분류에서Dev

CSS Fluid Image 문제

분류에서Dev

CSS stretch or fit background image

분류에서Dev

CSS background image align to center

분류에서Dev

Variation on CSS vertical image align

분류에서Dev

Correct way to image on css shape?

분류에서Dev

css image cut background transparent

분류에서Dev

positioning a link on a image using css

분류에서Dev

overlaying an image with text in Materialize CSS

분류에서Dev

HTML & CSS - Full Screen Image

분류에서Dev

Flip-Card CSS / HTML : 뒤집었을 때 카드 뒷면이 보이지 않음