CSS realizes that the left side of the webpage column is fixed and automatically adjusts the position when scrolling to the bottom

CSS realizes that the left side of the webpage column is fixed and automatically adjusts the position when scrolling to the bottom

Preview address:

https://ovsexia.gitee.io/leftfixed/

html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="js/jquery-1.10.1.min.js" type="text/javascript"></script>
<link href="css/layout.css" type="text/css" rel="stylesheet" />
<link href="css/style.css" type="text/css" rel="stylesheet" />
</head>
<div class="top"></div>
<div class="page">
  <div class="left">
    <div class="left_poi"></div>
    <div class="left_in">
      <p><br />< ...
    </div><!--left_in-->
    <script>
    $(window).scroll(function()
    {
        saction();
    });
    function action()
    {
        sj = 20; //Bottom interval st = $(window).scrollTop(); //Scroll bar height sd = $(".left_poi").offset().top;
        sd_h = $(".left_in").height();
        sb = $(".bottom").offset().top;
        sb_h = $(".bottom").height();
        rd_h = $(".right").height();
        bh = window.innerHeight;
        si = sb-sd_h;
        if(st>sd && rd_h>=sd_h){
            $(".left_in").addClass("on");
            if(st>si){
                sy = bh-(sb-st)+sj;
                $(".left_in").css({"top":"auto","bottom":sy+"px"});
            }else{
                $(".left_in").css({"top":"","bottom":""});
            }
        }else{
            $(".left_in").removeClass("on");
        }
    }
    </script>
  </div><!--left-->
  <div class="right"></div>
  <div class="clear"></div>
</div><!--page-->
<div class="bottom"></div>
</body>
</html>

CSS

@charset "utf-8";
.clear {clear:both; height:0 !important; width:0 !important; overflow:hidden; font-size:0;}
.top {width:100%; height:150px; background:#0CC;}
.bottom {width:100%; height:400px; background:#39C;}
.page {width:1200px; margin:20px auto; position:relative;}
.left {width:200px; float:left;}
.left_in {width:200px; background:#46bc67; border-top:3px solid #000; border-bottom:3px solid #000;}
.left_in.on {position:fixed; top:0;}
.left_poi {width:100%; height:1px; overflow:hidden;}
.right {width:960px; height:2100px; float:right; overflow:hidden; background:#FC3;}

Summarize

The above is the CSS that I introduced to you. How to fix the left side of the web page column and automatically adjust the position when scrolling to the bottom. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

<<:  Several situations that cause MySQL to perform a full table scan

>>:  This article will show you how JavaScript garbage collection works

Recommend

HTML line spacing setting methods and problems

To set the line spacing of <p></p>, us...

Detailed explanation of MySQL database paradigm

Preface: I have often heard about database paradi...

Implementation code for partial refresh of HTML page

Event response refresh: refresh only when request...

Using Nginx to implement grayscale release

Grayscale release refers to a release method that...

How to create Apache image using Dockerfile

Table of contents 1. Docker Image 2. Create an in...

Basic use of subqueries in MySQL

Table of contents 1. Subquery definition 2. Subqu...

Using js to achieve waterfall effect

This article example shares the specific code of ...

Basic commands for MySQL database operations

1. Create a database: create data data _name; Two...

How to remotely log in to the MySql database?

Introduction: Sometimes, in order to develop a pr...

Sample code for partitioning and formatting a disk larger than 20TB on centos6

1. Server environment configuration: 1. Check dis...

Detailed explanation of how to install MariaDB 10.2.4 on CentOS7

CentOS 6 and earlier versions provide MySQL serve...

Tutorial on installing and configuring MySql5.7 in Alibaba Cloud ECS centos6.8

The default MySQL version under the Alibaba Cloud...

MySQL master-slave configuration study notes

● I was planning to buy some cloud data to provid...