Fabric.js中的getScrollLeftTop()方法用於查找元素的滾動偏移量。此方法返回的對象包含“top”和“left”屬性,分別表示“top”和“left”偏移量。必須首先選擇頁麵中的HTML元素以通過此方法。
用法:
getScrollLeftTop(element)
參數:此方法接受如上所述和以下描述的單個參數:
- element:此參數用於指定必須為其找到滾動偏移量的HTML元素。
返回值:此方法返回一個包含“top”和“left”滾動偏移量作為屬性的對象。
下麵的示例演示了getScrollLeftTop()方法Fabric.js:
例:
HTML
<html>
<head>
<!-- Adding the Fabric.js library -->
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js">
</script>
<style>
/* Define the CSS classes to be used */
.box1 {
margin:25px;
width:400px;
height:400px;
background-color:red;
}
.box2 {
margin:25px;
width:700px;
height:300px;
background-color:green;
}
</style>
</head>
<body>
<h1 style="color:green;">
GeeksforGeeks
</h1>
<h3>
Fabric.js util.getScrollLeftTop() Method
</h3>
<div class="box1">
Element 1
</div>
<div class="box2">
Element 2
</div>
<script>
// Select the elements to be used
let elem =
document.querySelector('.box1');
let elem2 =
document.querySelector('.box2');
function getScrollOffsets() {
console.clear();
console.log(
"Current Left and Top Offsets are:"
);
// Find the scrolled left and top offsets
console.log(
fabric.util.getScrollLeftTop(elem)
);
console.log(
fabric.util.getScrollLeftTop(elem2)
);
}
// Repeatedly call the function
// to observe the values
setInterval(getScrollOffsets, 1000);
</script>
</body>
</html>
輸出:
相關用法
- Lodash _.method()用法及代碼示例
- Node.js Http2ServerRequest.method用法及代碼示例
- Node.js http.IncomingMessage.method用法及代碼示例
- Javascript dataView.getInt16()用法及代碼示例
- Collect.js toArray()用法及代碼示例
- Javascript RegExp toString()用法及代碼示例
- Node.js URLSearchParams.has()用法及代碼示例
- JavaScript Math cosh()用法及代碼示例
- HTML DOM isEqualNode()用法及代碼示例
- JavaScript Date toLocaleTimeString()用法及代碼示例
- Node.js crypto.createHash()用法及代碼示例
- Node.js process.send()用法及代碼示例
- Node.js writeStream.clearLine()用法及代碼示例
- Javascript Number isSafeInteger()用法及代碼示例
- HTML DOM History go()用法及代碼示例
- Node.js fs.link()用法及代碼示例
- JavaScript Math random()用法及代碼示例
- JavaScript Math round()用法及代碼示例
- Javascript toString()用法及代碼示例
- Javascript Number.isInteger( )用法及代碼示例
- Javascript Number.isFinite()用法及代碼示例
- Javascript toFixed()用法及代碼示例
注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 Fabric.js getScrollLeftTop() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。