Draw A Diagonal Line Through A Box - jQuery diagonal.js

Draw A Diagonal Line Through A Box - jQuery diagonal.js
File Size: 14.2 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

diagonal.js is a minimal jQuery plugin to draw a responsive diagonal line through a container element that automatically adapts to the width of the container on window resize.

How to use it:

1. Create a container where you want to draw the diagonal line.

<div class="box"></div>
.box{
  position:relative;
  margin:50px auto;
  width:100px;
  height:300px;
  box-sizing:border-box;
  border:1px solid #333;
}

2. Insert the jquery.diagonal.js after jQuery library.

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" 
        integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" 
        crossorigin="anonymous">
</script>
<script src="src/jquery.diagonal.js"></script>

3. Get the degree of the diagonal.

var deg = $.diagonal.deg(".box");

4. Draw the the diagonal line inside the container and specify the color as per your needs.

$(".box").diagonal({
  deg: deg,
  color: '#fff'
});

5. Decide whether to adapt to the width of the container.

$(".box").diagonal({
  deg: deg,
  color: '#fff',
  isrwd: true
});

This awesome jQuery plugin is developed by fdjkgh580. For more Advanced Usages, please check the demo page or visit the official website.