【问题标题】:position of my image when i change my mobile view更改移动视图时图像的位置
【发布时间】:2016-04-03 10:18:59
【问题描述】:

我的图像位置有一个小问题,所以问题出在这里,我有我的纵向视图,我滑动我的图像,当我切换我的视图(纵向到横向)时,我的图像不再居中。我的问题是图像的边距仍然与纵向视图相同,我不知道如何更改。

我已经尝试更改图像的边距,但无事可做,它仍然是我使用的第一个视图边距。

所以这里是Js/Jq:

function puceTransition(front) {
    var wrapImg = $('.wrapImage');
    var margeLeft = 0;

if(front) {
    if (stateImg == "back") {
        stateImg = "front";

        margeLeft = $('#myImageBack').css("marginLeft").replace("px", "");

        $('#frontImg').addClass('select');
        $('#backImg').removeClass('select');

        $('#myImageBack').animate({opacity: "0.5", marginLeft: ((imgFront + widthImg1 + myButtonRight)) + "px"}, "normal");
        $('#myImageFront').animate({opacity: "1.0", marginLeft: parseInt(margeLeft) + "px"}, "normal");

        $('.imgTitleBack').hide();
        $('.imgTitleFront').show();

        $('#imgButtonLeft').animate({opacity: "0.5"});
        $('#imgButtonRight').animate({opacity: "1.0"});
    }
} else {
    if (stateImg == "front") {
        stateImg = "back";

        margeLeft = $('#myImageFront').css("marginLeft").replace("px", "");

        $('#backImg').addClass('select');
        $('#frontImg').removeClass('select');

        $('#myImageFront').animate({opacity: "0.5", marginLeft: (((-imgFront) + (-widthImg1) + myButtonLeft)) + "px"}, "normal");
        $('#myImageBack').animate({opacity: "1.0", marginLeft: parseInt(margeLeft) + "px"}, "normal");

        $('.imgTitleBack').show();
        $('.imgTitleFront').hide();

        $('#imgButtonLeft').animate({opacity: "1.0"});
        $('#imgButtonRight').animate({opacity: "0.5"});
    }
}
}

这里是css:

    .myImage { display: block; position: relative; width: 450px; margin: 0 auto; }
    .myImage.second { margin: -240px 0 0 670px; }
    .myImageAirport { display: block; position: relative; width: 450px; margin: 0 auto; }
    .myImageAirport.second { margin : -220px 0 0 670px; }

【问题讨论】:

    标签: javascript image css mobile position


    【解决方案1】:

    只需将此 css 添加到您的图像类中

    .myImage {
    display: block;
    margin-right: auto;
    margin-left: auto;
    }
    

    应该可以了!

    【讨论】:

    • 嗯,我已经用我的边距做到了:0 auto;但我尝试了你的代码,但仍然发生同样的事情:s
    猜你喜欢
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    • 2022-10-13
    • 1970-01-01
    • 2014-08-06
    • 1970-01-01
    相关资源
    最近更新 更多