简体   繁体   English

当滚动时,如何将图像粘贴到div的左侧?

[英]How do you stick an image to the left side of a div when upon scroll, it moves with the div?

Currently, I'm making a personal website and I have an about me section. 目前,我正在建立一个个人网站,并且有一个关于我的部分。 The about me section has a lot of text and I want an image to be positioned the left side of the div (contains all the text). “关于我”部分包含很多文本,我希望将图像放置在div的左侧(包含所有文本)。

As you scroll through the text, I want the image to follow, so that you can see it as you scroll down the div. 当您滚动文本时,我希望图像紧随其后,以便您在向下滚动div时可以看到它。 This means that the image is moving (pushing down) as scroll happens. 这意味着随着滚动的发生,图像正在移动(向下推动)。 How would you do this? 你会怎么做?

To make matters a little more complicated, I have ap within the div that is hidden and is toggled on or off with jquery. 让事情变得更加复杂的是,我在div中有一个ap,它是隐藏的,并使用jquery进行了开关。 This adds more height to the original div. 这会增加原始div的高度。

HTML: HTML:

<section id="about" class="container content-section">
    <div class="row">
        <div class="col-xs-6 col-md-4">
            <img src="img/pic.jpeg" height="300" width="300" class="bio-pic" style="display:inline">
        </div>
        <div class="col-xs-12 col-sm-6 col-md-8" style="display:inline; ">
            <h2>About Me</h2>
            <h4>the present</h4>
            <p>Hi! I'm Ashley.</p>
            <h4 class="thepast">the past <i class="fa fa-angle-down"></i></h4>
            <p class="thepasttext">text of about ~300 words or more</p>
            <h4>the future</h4>
            <p>small blurb of text</p>
        </div>
    </div>
</section>

CSS: CSS:

.thepasttext {
    display: none;
}

jQuery: jQuery的:

$(document).ready(function(){
    $('.thepast').click(function(){
        $('.thepasttext').toggle();
    });
});

You should try in CSS add 您应该尝试在CSS中添加

position: fixed;

to your div with img. 到您的div与img。

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

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