Проблемы с поворотом изображения в IE <9 - PullRequest
0 голосов
/ 15 марта 2011

Я пытаюсь повернуть изображение, а также изменить его размер / перетащить с помощью пользовательского интерфейса Jquery.

Прекрасно работает во всех современных браузерах, но IE <9 имеет проблемы с положением изображения, когда оно перемещается, а затем поворачивается с помощью ползунков. </p>

Проблема, которую я считаю, заключается в том, что я использую obj.style.top и obj.style.left в функции IE, и это, возможно, конфликтует с position.left в jQuery?

Пример по адресу:

http://www.silverink.com/TEMP/rotateTest/

Любые предложения будут великолепны. Спасибо

Вот Javascript, который я использую:

    var objsrc = $('#uploadedImage').attr('src');

    //Set variable for width and height of uploaded image
    var origWidth = ($('#uploadedImage').attr('width'));
    var origHeight = ($('#uploadedImage').attr('height'));

    //Set newWidth and newHeight initially to origWidth and origHeight
    var newWidth = origWidth;
    var newHeight = origHeight;

    //INITIAL POSITION VALUES
    var newPositionLeft = $('#uploadedImage').position().left;
    var newPositionTop = $('#uploadedImage').position().top;

    //set dimensions of drag div to be the same as the image div
    $("#dragDiv").css("width",origWidth).css("height",origHeight);

    //Set initial rotateVal
    var rotateVal = 0;

    //set Initial ScaleVal
    var scaleVal = 1;

//JQUERY ONLOAD
    $(document).ready(function() {          


    // DRAG //
    //Set dragDiv as draggable, then on drag set position of uploadedImage to reflect
     $("#dragDiv").draggable({ 
         cursor: 'move',
         start: function(event,ui) {
            $('#uploadedImage').stop().animate({opacity: 0.6}); 
            $('#fadeOutPng').stop().animate({opacity: 0.3});
         },
         drag: function(event,ui) {
            $('#uploadedImage').css("left",ui.position.left).css("top",ui.position.top);
            $('this').css("left",ui.position.left).css("top",ui.position.top);
         },
         stop: function(event,ui) {
            $('#uploadedImage').stop().animate({opacity: 1}); 
            $('#fadeOutPng').stop().animate({opacity: 1});

            // THESE 2 LINES KEEP THE IMAGE CENTRED ON THE MOUSE WHEN IT IS ROTATED... THE ROTATE FUNCTION REQUIRES AN UPDATED POSITION
            newPositionLeft = ui.position.left;
            newPositionTop = ui.position.top;

            $("#deBug").html("src="+objsrc+"<br />width="+newWidth+"<br />height="+newHeight+"<br />top="+$('#uploadedImage').position().top+"<br />left="+$('#uploadedImage').position().left + "<br />newPositionLeft="+newPositionLeft+"<br />newPositionTop="+newPositionTop+"<br />Rotate val="+rotateVal+"<br />"+ui.position.left);
         }
     });

        // ROTATE SLIDER //
        $("#rotateSlider").slider({
        range: "max",
        min: 0,
        max: 360,
        step: 10,
        value: 0,
        slide: function( event, ui ) {
            rotateVal = ui.value;


            //IE ROTATE
            if(($.browser.msie) && (parseInt($.browser.version, 10) < 9)){
                    rotate(uploadedImage,ui.value,true,newWidth,newHeight);
                }
            //SAFARI GOOGLE ROTATE
            else if ($.browser.webkit) {
                $('#uploadedImage').attr('style','-webkit-transform: rotate('+rotateVal+'deg);').css("width",newWidth).css("height",newHeight).css("left",newPositionLeft).css("top",newPositionTop)
                }
            //MOZ ROTATE
            else if ($.browser.mozilla) {
                $('#uploadedImage').attr('style','-moz-transform: rotate('+rotateVal+'deg);').css("width",newWidth).css("height",newHeight).css("left",newPositionLeft).css("top",newPositionTop)
                }
            //CSS3 STANDARD ROTATE (IE9, OPERA)
            else{
                $('#uploadedImage').attr('style','transform: rotate('+rotateVal+'deg)').css("width",newWidth).css("height",newHeight).css("left",newPositionLeft).css("top",newPositionTop)
                };

            $("#deBug").html("src="+objsrc+"<br />width="+newWidth+"<br />height="+newHeight+"<br />top="+$('#uploadedImage').position().top+"<br />left="+$('#uploadedImage').position().left + "<br />newPositionLeft="+newPositionLeft+"<br />newPositionTop="+newPositionTop+"<br />Rotate val="+rotateVal);
            }
        });

        //set up resize slider
        $("#resizeSlider").slider({
        range: "max",
        min: 20,
        max: 100,
        value: 100,
        //step: 0.1,
        slide: function( event, ui ) {
            newWidth = (origWidth * (ui.value / 100));
            newHeight = (origHeight * (ui.value / 100));
            $('#uploadedImage').css("width",newWidth).css("height",newHeight);
            $('#dragDiv').css("width",newWidth).css("height",newHeight);
            scaleVal = ui.value/100;
        }
        });

 }); //END ONREADY FUNCTIONS



// IE ROTATE //
function rotate(obj, angle, centered, thisNewWidth, thisNewHeight){
   var rad = angle * Math.PI * 2 / 360,
      cos = Math.cos(rad),
      sin = Math.sin(rad);


   dragDiv.style.filter = obj.style['-ms-filter'] = 'progid:DXImageTransform.Microsoft.Matrix(sizingMethod="auto expand", M11 = ' + cos + ', M12 = ' + (-sin) + ', M21 = ' + sin + ', M22 = ' + cos + '); ';

   obj.style.filter = obj.style['-ms-filter'] = 'progid:DXImageTransform.Microsoft.Matrix(sizingMethod="auto expand", M11 = ' + cos + ', M12 = ' + (-sin) + ', M21 = ' + sin + ', M22 = ' + cos + ')';

   if (centered) {
      if (obj.style.position != 'absolute' && obj.style.position != 'fixed') obj.style.position = 'relative';

      //Set the rotating image top and left centered - it's the height minus the offsetheight (height from top to bottom as rotated) divided by 2 then add the new position top
      var newTop = newPositionTop + ((thisNewHeight - obj.offsetHeight) / 2);
      var newLeft = newPositionLeft + ((thisNewWidth - obj.offsetWidth) / 2);

      obj.style.top = newTop;
      obj.style.left = newLeft;

      dragDiv.style.top = newTop;
      dragDiv.style.left = newLeft;
   }
}

Ой, извините, если код не совсем корректен, просто взломайте mo для доказательства концепции!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...