javascript - 当我改变我的移动 View 时我的图像的位置

标签 javascript image css mobile position

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

我已经尝试更改我的图像边距,但无济于事,它仍然占用我使用的第一个 View 边距。

所以这里是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; }

最佳答案

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

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

它应该有效!

关于javascript - 当我改变我的移动 View 时我的图像的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34512614/

相关文章:

javascript - 动态更改 Bootstrap 弹出窗口的模板

javascript - 溢出 HTML 框架元素之外的内容

java - Mac 上的 SWT 图像按钮不起作用

css - 缩小(缩放)图像以适合 parent 而不显示背景

html - 如何插入背景图片以覆盖大部分网页?

javascript - 为什么删除图标按钮在以下情况下没有附加 <select>?

javascript - 为什么可观察源在竞赛(或合并)中使用时不发出值,但在我手动订阅它时发出值

带有大量图像的 iPhone 桌面 View

javascript - 固定在 Flexbox 中的位置在 chrome 和 safari/firefox 之间表现不同

jquery - Jquery 与 CSS 工具提示的性能?