.cssClip()


.cssClip( [dimensions ] )Returns: jQueryversion added: 1.12

Description: Getter/setter for an object version of the CSS clip property.

  • .cssClip( [dimensions ] )

    • dimensions
      Type: Object
      When setting the CSS clip property, specify the top, right, bottom and left, properties to use the rect() style.

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>cssClip demo</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.13.3/themes/smoothness/jquery-ui.css">
<style>
.clipped {
position: absolute;
width: 150px;
height: 150px;
background: #3b679e;
background: linear-gradient(to bottom, #3b679e 0%, #2b88d9 50%, #207cca 51%, #7db9e8 100%);
}
</style>
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://code.jquery.com/ui/1.13.3/jquery-ui.js"></script>
</head>
<body>
Click anywhere!
<div class="clipped"></div>
<script>
var clippings = [
{
top: 10,
right: 50,
bottom: 50,
left: 5
},
{
top: 0,
right: 150,
bottom: 150,
left: 0
}
];
var index = 1;
var box = $( ".clipped" ).cssClip( clippings[ 0 ] );
$( document ).click(function() {
box.animate( {
clip: clippings[ index++ % 2 ]
}, 2000 );
});
</script>
</body>
</html>

Demo: