简体   繁体   English

jQuery左边距不起作用

[英]jQuery margin-left not working

I'm trying to animate a div to basically slide left and move out of view, but it's simply not working and i can't figure out why. 我正在尝试为div设置动画以使其基本向左滑动并移出视线,但是它根本无法正常工作,我不知道为什么。 I've added the code below and, of course, i've included the jQuery script. 我添加了下面的代码,当然,我包括了jQuery脚本。

HTML 的HTML

<div class="site-main" id="main">

<div class="main-content" id="main-content">
    <div class="closeContent"><i class="fa fa-times"></i></div>
    <div class="content-area" id="primary">

        <article class="post-22 page type-page status-publish hentry" id="post-22">

           <div class="innerRightCol">
               <h2>Text</h2>
           </div>

        </article><!-- #post-## -->
    </div><!-- #primary -->
</div><!-- #main-content -->

</div>

CSS 的CSS

.site-main {
    background: none repeat scroll 0 0 rgba(0, 0, 0, 0.75);
    margin-left: 255px;
    position: relative;
    top: 0;
    width: 560px;
}

JS JS

$(document).ready(function() {
    $(".closeContent").click(function (){
        $(".main-content").animate({"margin-left": '-=255px'});
    });
});

.closeContent为空白,除非添加一些文本或为div提供宽度和高度,否则您无法单击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM