jQuery plugin to implement floating menu

jQuery plugin to implement floating menu

Learn a jQuery plugin every day - floating menu, for your reference, the specific content is as follows

Floating menu

This is another very common effect, using a common feature of the a tag - anchor

The effect is as follows

Code section

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>Floating menu</title>
  <script src="js/jquery-3.4.1.min.js"></script>
  <style>
   *{
    margin: 0px;
    padding: 0px;
    user-select: none;
   }
   .item{
    border: 1px solid lightgray;
    margin: 10px;
    height: 400px;
    border-radius: 5px;
    position: relative;
   }
   .head{
    background-color: lightgray;
    height: 30px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    text-indent: 10px;
    position: absolute;
    top: 0px;
    width: 100%;
   }
   .fbox{
    position: fixed;
    top: 20%;
    bottom: 20%;
    right: 20px;
    width: 150px;
    border: 1px solid lightgray;
    background-color: white;
    border-radius: 5px;
   }
   .main{
    position: absolute;
    top: 30px;
    width: 100%;
    bottom: 0px;
    overflow:auto;
   }
   .main ul{
    margin-left: 30px;
   }
   a{
    color: gray;
   }
  </style>
 </head>
 <body>
 </body>
</html>
<script>
 $(document).ready(function(){
  //Add test dom and generate test data var arr = [];
  for(var i = 0;i<50;i++){
   var id = 'id'+i;
   var $dom = $("<div class='item' id='"+id+"'><div class='head'>"+id+"</div></div>");
   $dom.appendTo($("body"));
   arr.push(id);
  }
  //Call method $.fmenu(arr);
 })
 $.extend({
  fmenu:function(arr){
   $(".fbox").remove();
   var $fbox = $("<div class='fbox'></div>");
   var $head =$("<div class='head'>Floating menu</div>");
   var $main = $("<div class='main'></div>");
   var $ul = $("<ul class='ul'></ul>")
   $ul.appendTo($main);
   $head.appendTo($fbox);
   $main.appendTo($fbox);
   $fbox.appendTo($("body"));
   arr.forEach(item=>{
    var $li = $("<li><a href='#"+item+"'>"+item+"</a></li>");
    $li.appendTo($ul);
   })
  }
 })
</script>

Explanation of ideas

  • The a tag is not only used for hyperlinks, but can also be used as a channel for downloading files and for navigating document locations.
  • For example, if you have a set of attributes that can be found in the current page, such as #id and .class, you can use js to get the selected path and then get its document height, and then let the browser scroll to the corresponding height.
  • And a.href is directly equal to the selected object, so the anchor point can be directly positioned at the corresponding position.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to use CSS3+JQuery to implement a floating wall menu
  • JQuery gets the visual area size and document size and creates a floating menu example
  • jQuery+CSS3 implements a fixed top navigation menu with floating effect imitating the petal network
  • jQuery implementation of the secondary menu effect when the mouse hovers

<<:  Solution to the failure of loading dynamic library when Linux program is running

>>:  ERROR 1045 (28000): Access denied for user ''root''@''localhost'' (using password: YES) Practical solution

Recommend

Some problems you may encounter when installing MySQL

Question 1: When entering net start mysql during ...

Detailed explanation of padding and abbreviations within the CSS box model

As shown above, padding values ​​are composite at...

Web interview Vue custom components and calling methods

Import: Due to project requirements, we will enca...

Linux /etc/network/interfaces configuration interface method

The /etc/network/interfaces file in Linux is used...

How to automatically start RabbitMq software when centos starts

1. Create a new rabbitmq in the /etc/init.d direc...

How to create a simple column chart using Flex layout in css

The following is a bar chart using Flex layout: H...

Solution to the blank page after vue.js packaged project

I believe that many partners who have just come i...

CSS navigation bar menu with small triangle implementation code

Many web pages have small triangles in their navi...

Common commands for mysql authorization, startup, and service startup

1. Four startup methods: 1.mysqld Start mysql ser...

Several common redirection connection example codes in html

Copy code The code is as follows: window.location...

Summary of several APIs or tips in HTML5 that cannot be missed

In previous blog posts, I have been focusing on so...

Complete steps to configure IP address in Ubuntu 18.04 LTS

Preface The method of configuring IP addresses in...

How to implement the singleton pattern in Javascript

Table of contents Overview Code Implementation Si...

JS interview question: Can forEach jump out of the loop?

When I was asked this question, I was ignorant an...