Dhaval Kapupara Dhaval Kapupara - 6 months ago 28
CSS Question

rotate text in model popup?

I am using this code to rotate text in model but this code is not working in model popup?

var rotation = 0;

jQuery.fn.rotate = function (degrees) {
$(this).css({
'-webkit-transform': 'rotate(' + degrees + 'deg)',
'-moz-transform': 'rotate(' + degrees + 'deg)',
'-ms-transform': 'rotate(' + degrees + 'deg)',
'transform': 'rotate(' + degrees + 'deg)'
});
};

$('#btnRotateRight').click(function () {
rotation += 5;
$('.rotate').rotate(rotation);
});

$('#btnRotateLeft').click(function () {
rotation -= 5;
$('.rotate').rotate(rotation);
});


Then following code is Model popup.

$("#ViewDetail").append('<div class="modal-content"><div class="modal-header"><button id="btnRotateLeft" type="button">Rotate Left</button> <button id="btnRotateRight" type="button">Rotate Right</button><button type="button" class="close" data-dismiss="modal">&times;</button><h4 class="modal-title">Preview Cake</h4> </div> <div class="modal-body" style="text-align:center;"><div style="background-image:url(' + data.PrevRoundImg + ');max-width:320px;height:320px;background-repeat: no-repeat;padding-top:40%;" ><div class="rotate"><b id="msgtext" style="font-family:cursive;color:black; text-shadow: 0 0 3px White;font-size:20px;" >' + ckemsg + '</b></div></div></div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div></div>');

Answer

Your script is not working because you are register event $('#btnRotateRight').click( and $('#btnRotateLeft').click( on dynamic content so for that case you need to register event after render the element in the page or use Jquery on event like as below:

    $(document).on("click", "#btnRotateRight", function () {
        rotation += 5;
        $('.rotate').rotate(rotation);
    });

    $(document).on("click", "#btnRotateLeft", function () {
        rotation -= 5;
        $('.rotate').rotate(rotation);
    });

or register event after render the elements in the page like as below:

    $("#btnCheck").click(function () {
        $("#ViewDetail").append('<div class="modal-content"><div class="modal-header"><button id="btnRotateLeft" type="button">Rotate Left</button> <button id="btnRotateRight" type="button">Rotate Right</button><button type="button" class="close" data-dismiss="modal">&times;</button><h4 class="modal-title">Preview Cake</h4> </div> <div class="modal-body" style="text-align:center;"><div style="background-image:url(' + data.PrevRoundImg + ');max-width:320px;height:320px;background-repeat: no-repeat;padding-top:40%;" ><div class="rotate"><b id="msgtext" style="font-family:cursive;color:black; text-shadow: 0 0 3px White;font-size:20px;" >' + ckemsg + '</b></div></div></div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div></div>');
        RegisterEvents();
    });
    var rotation = 0;
    function RegisterEvents() {
        jQuery.fn.rotate = function (degrees) {
            $(this).css({
                '-webkit-transform': 'rotate(' + degrees + 'deg)',
                '-moz-transform': 'rotate(' + degrees + 'deg)',
                '-ms-transform': 'rotate(' + degrees + 'deg)',
                'transform': 'rotate(' + degrees + 'deg)'
            });
        };
        $('#btnRotateRight').click(function () {
            rotation += 5;
            $('.rotate').rotate(rotation);
        });
        $('#btnRotateLeft').click(function () {
            rotation -= 5;
            $('.rotate').rotate(rotation);
        });
    }